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 usernameemail(str): Your Git emailrepo_url(str): URL of the public repositorylocal_path(str): Path to the local directory you want to pushcommit_message(str): Your commit messagebranch_name(str, optional): Branch name to push to (defaults to "main")
Features in Detail
- Automatic Git Configuration: Sets up Git user name and email locally for the operation
- Repository Management:
- Initializes Git repository if not already initialized
- Adds remote origin if not present
- Branch Handling:
- Creates new branch if it doesn't exist
- Switches to existing branch if it exists
- Smart Push:
- Only commits if there are changes
- Pushes to the specified branch
- 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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file gitpushagent-0.1.2.tar.gz.
File metadata
- Download URL: gitpushagent-0.1.2.tar.gz
- Upload date:
- Size: 4.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fb409aaf8c68ac7adba7713ec42f4e5bfa280e9239ac5f12ed6016db3b2337dc
|
|
| MD5 |
d4aa58b98286c2ae465b0cd013547388
|
|
| BLAKE2b-256 |
b0817fc187809e8775a0bd46eee7d267e91cdcc801d866dd0c131537972a2543
|
File details
Details for the file gitpushagent-0.1.2-py3-none-any.whl.
File metadata
- Download URL: gitpushagent-0.1.2-py3-none-any.whl
- Upload date:
- Size: 5.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1f8f4269043e0cca9309799e95d90dd93b9630e4e95597337fdd29667e74ee56
|
|
| MD5 |
c15491701830dce1b453c680d4fceaa7
|
|
| BLAKE2b-256 |
dfbc5952ff9cd398acbc209c2a0f2898864ce4a310e0fd1b2dec37c1c10fdf37
|