Skip to main content

A simple Python package to automate Git push operations

Project description

GitPushAgent

A simple Python package that automates Git push operations with a single function call. Perfect for automating Git workflows and CI/CD pipelines.

Features

  • Simple one-function interface
  • Automatic Git configuration
  • Branch management (create/switch)
  • Repository initialization
  • Error handling
  • Local Git config management

Installation

You can install GitPushAgent using pip:

pip install gitpushagent

Usage

Basic Usage

from gitpushagent import push

# Push to main branch
push(
    username="your-username",
    email="your.email@example.com",
    repo_url="https://github.com/username/repo.git",
    local_path="/path/to/your/local/directory",
    commit_message="Your commit message"
)

Using a Different Branch

from gitpushagent import push

# Push to a specific branch
push(
    username="your-username",
    email="your.email@example.com",
    repo_url="https://github.com/username/repo.git",
    local_path="/path/to/your/local/directory",
    commit_message="Your commit message",
    branch_name="feature-branch"  # Optional, defaults to "main"
)

Error Handling

from gitpushagent import push, GitPushError

try:
    push(
        username="your-username",
        email="your.email@example.com",
        repo_url="https://github.com/username/repo.git",
        local_path="/path/to/your/local/directory",
        commit_message="Your commit message"
    )
except GitPushError as e:
    print(f"An error occurred: {e}")
except ValueError as e:
    print(f"Invalid input: {e}")

Parameters

  • username (str): Your Git username
  • email (str): Your Git email
  • repo_url (str): URL of the public repository
  • local_path (str): Path to the local directory you want to push
  • commit_message (str): Your commit message
  • branch_name (str, optional): Branch name to push to (defaults to "main")

Features in Detail

  1. Automatic Git Configuration: Sets up Git user name and email locally for the operation
  2. Repository Management:
    • Initializes Git repository if not already initialized
    • Adds remote origin if not present
  3. Branch Handling:
    • Creates new branch if it doesn't exist
    • Switches to existing branch if it exists
  4. Smart Push:
    • Only commits if there are changes
    • Pushes to the specified branch
  5. Error Handling:
    • Validates all inputs
    • Provides clear error messages
    • Cleans up local Git config after operation

Requirements

  • Python 3.7 or higher
  • Git installed on your system

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

gitpushagent-0.1.0.tar.gz (4.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

gitpushagent-0.1.0-py3-none-any.whl (5.2 kB view details)

Uploaded Python 3

File details

Details for the file gitpushagent-0.1.0.tar.gz.

File metadata

  • Download URL: gitpushagent-0.1.0.tar.gz
  • Upload date:
  • Size: 4.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.2

File hashes

Hashes for gitpushagent-0.1.0.tar.gz
Algorithm Hash digest
SHA256 c1fddefdaa1b08134a46ba0d6e2eaf5a8641f3d83beda05dab52c703d9c85adc
MD5 96fb255fb1888a6062366c4c11338469
BLAKE2b-256 be74235609bc875c4ff455e22d3173c13e9a9b5ecc93066411672506eb582e1f

See more details on using hashes here.

File details

Details for the file gitpushagent-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: gitpushagent-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 5.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.2

File hashes

Hashes for gitpushagent-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 982dfa5ef479da54b5c44520c5eff6651a7c6cb903a1c707c5164ca4374774a4
MD5 56cd59e1d1791c28a88cdc6d9d89dcd8
BLAKE2b-256 24cb9f23f52008eeef8b6d0651367d3f8b2189f66f84cb58fac2c0809dd73e05

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page