auto-git
A zero-dependency command-line utility written in standard Python to automate routine Git tasks: repository initialization, status checking, staging, committing, branch management, commit rollbacks, and GitHub Pull Request creation.
Technical Overview & Features
- Repository Initialization: Detects if the current directory is a Git repository. If not initialized, it can run
git init, configure default branch names (main), and attach GitHub remote URLs. - Git Porcelain Parsing: Parses
git status -z --porcelainoutput using NUL delimiters. Safely handles filenames with spaces, Unicode characters, and rename/copy states without shell escaping issues. - Merge Conflict Detection: Identifies unmerged conflict status codes (
UU,AA,DD, etc.) and halts commit operations to prevent committing unresolved conflict markers. - Branch Management: Supports switching between existing branches, creating new feature branches, and protecting the default branch (
main) by offering to redirect uncommitted changes to a new feature branch. - Detached HEAD Resolution: Detects detached HEAD states and prompts for target branch resolution or creates temporary branches automatically when running non-interactively.
- Interactive Log & Rollback: Displays local and remote commit history side-by-side and executes soft (
--soft), mixed (--mixed), or hard (--hard) resets to chosen target commits. - GitHub CLI & Browser PR Integration: Opens Pull Requests automatically using GitHub CLI (
gh pr create) when available, or generates and launches a GitHub web browser comparison link (https://github.com/user/repo/compare/...) ifghis unauthenticated or not installed. - Terminal User Interface (TUI): Opt-in interactive curses interface (
auto-git --tui) offering dashboard view, keyboard-driven navigation (↑/↓/j/k), stage/commit wizard, branch switcher/creator, commit rollback picker, and pull request builder. - Subprocess Security: All Git commands execute via list arguments without
shell=True, eliminating shell injection risks. - Zero External Dependencies: Operates strictly using Python standard library modules (
subprocess,argparse,os,sys,re,datetime,urllib,webbrowser,curses).
Architecture & Internal Design
+-------------------------------+
| CLI Invocation |
| (auto-git / -y) |
+---------------+---------------+
|
v
+-------------------------------+
| Repo & State Inspection |
| git status -z --porcelain |
+---------------+---------------+
|
+-------------------------+-------------------------+
| | |
v v v
+--------------------+ +--------------------+ +--------------------+
| Merge Conflict? | | Detached HEAD? | | Default Branch? |
| Stop and warn user | | Prompt/auto-create | | Offer feature |
| before staging | | branch | | branch redirect |
+--------------------+ +--------------------+ +--------------------+
| | |
+-------------------------+-------------------------+
|
v
+-------------------------------+
| Stage & Commit |
| git add -A / git commit |
+---------------+---------------+
|
v
+-------------------------------+
| Remote Push |
| git push origin <head> |
+---------------+---------------+
|
v
+-------------------------------+
| Pull Request Creation |
| gh pr create OR browser link |
+-------------------------------+
1. Subprocess Execution & Security Model
All command executions are routed through run_command(), which wraps subprocess.run().
- List Arguments: Commands are passed as lists of strings (e.g.,
["git", "commit", "-m", msg]), bypassing shell invocation (shell=False). Arguments containing spaces, quotes, or special characters are passed directly to the executable binary. - UTF-8 Character Decoding: Standard streams output is parsed with
encoding="utf-8"anderrors="replace", preventing terminal locale encoding crashes on non-ASCII paths.
2. Machine-Readable Git Status Parsing
Rather than parsing standard line-based git status output (which quotes special characters and wraps spaces), auto_git uses git status -z --porcelain:
- NUL Delimiters (
\x00): Tokens are split by\x00bytes. Filenames containing spaces, quotes, or non-ASCII characters are returned in raw form. - Rename/Copy Resolution: Renamed (
R) and copied (C) status codes are followed by two NUL-terminated strings (the new path and the original source path), which are parsed without path string truncation.
3. Branch & State Management
- Detached HEAD Detection:
is_detached_head()executesgit symbolic-ref -q HEAD. A non-zero return code indicates detached HEAD state. - Default Branch Detection:
get_default_branch()resolves default branch targets by checkingrefs/remotes/origin/HEAD, parsinggit remote show origin, and checking local branch existence (main,master,develop). - Feature Branch Redirection: When working on the default branch with uncommitted changes,
move_changes_to_feature_branch()stashes uncommitted changes, creates a feature branch, resets the local default branch to matchorigin, and pops the stash onto the new feature branch.
4. Interactive Rollback Mechanism
When --rollback (-r) is invoked:
- Executes
git fetch originto update remote references. - Formats recent commit history (
git log --oneline -n 15) for both local HEAD and remote tracking branches. - Validates target selection using
git cat-file -t <commit_hash>. - Applies
git reset [--soft | --mixed | --hard] <commit_hash>.
Installation & Setup
Option 1: Install from PyPI (Recommended)
# Core CLI (Zero external dependencies)
pip install auto-git-cli
# With TUI support
pip install auto-git-cli[tui]
[!WARNING] TUI Status (Beta / Under Development): The Terminal User Interface (
auto-git-tuiorauto-git --tui) is currently under active development and is considered experimental. It may contain bugs or visual glitches on certain terminals. The core CLI (auto-git) is stable and recommended for routine usage.
Option 2: Install via pip (Local Editable Mode)
git clone https://github.com/Himanshu001-cpu/auto-git.git
cd auto-git
pip install -e .
# Or with TUI support:
pip install -e ".[tui]"
After installation, auto-git and auto-git-tui are available globally in your PATH.
Option 3: Run directly as a Python module
python -m auto_git [options]
Command Options & Usage
auto-git [options]
| Option | Long Option | Description |
|---|---|---|
-h |
--help |
Show help message and exit. |
-v |
--version |
Show program version and exit. |
-b <branch> |
--branch <branch> |
Switch to or create the specified branch. |
-m <msg> |
--message <msg> |
Use a custom commit message (skips input prompt). |
-y |
--yes |
Non-interactive mode: auto-generate commit message, skip prompts, and push. |
-r |
--rollback |
Display local & remote commit history and perform an interactive reset. |
-p |
--pull-request |
Open a GitHub Pull Request targeting the default branch. |
--tui |
Launch the interactive Terminal User Interface (Linux/macOS). | |
--no-push |
Stage and commit changes locally without pushing to remote. | |
--dry-run |
Display simulated actions without modifying repository state. |
Examples
1. Interactive Run
Stages all changes, displays status summary, prompts for commit message, and pushes to remote:
auto-git
2. Automated Script / CI Run (--yes)
Stages changes, auto-generates timestamped commit message, and pushes without interactive prompts:
auto-git -y
3. Switch/Create Branch & Commit
auto-git -b feature/auth-system -m "feat: implement OAuth login"
4. Dry Run Simulation
Preview actions without changing repository state:
auto-git --dry-run
5. Rollback Commits
Interactively inspect local and remote commit history, then execute a reset:
auto-git -r
6. Interactive Terminal User Interface (TUI Mode)
Launch the old-school keyboard-driven TUI:
auto-git --tui
# or directly via dedicated command:
auto-git-tui
- Navigation:
↑/↓orj/k - Select / Execute:
Enter - Back / Cancel:
Esc/q
Development & Testing
Running Tests
Install development dependencies and run pytest:
pip install -r requirements-dev.txt
pytest
Code Formatting & Linting
ruff check .
black --check .
Project Metadata & GitHub Configuration
- Project Description: Zero-dependency CLI tool to automate Git add, commit, branch creation, commit rollback, and GitHub PRs.
- Topics:
git,automation,cli,python,github,developer-tools - License: GPLv3
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 auto_git_cli-1.0.1.tar.gz.
File metadata
- Download URL: auto_git_cli-1.0.1.tar.gz
- Upload date:
- Size: 46.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
844629df5a018d9da50cd8a8a5b366735c971fffdf0b5d3c09689b6b2fa2a1d9
|
|
| MD5 |
fa48382d1aab00c57ac84724dd4895e9
|
|
| BLAKE2b-256 |
40bbbfdf79540123d971de4582db8e15cfe1cf4298cd39082036655138570122
|
Provenance
The following attestation bundles were made for auto_git_cli-1.0.1.tar.gz:
Publisher:
publish-pypi.yml on Himanshu001-cpu/auto-git
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
auto_git_cli-1.0.1.tar.gz -
Subject digest:
844629df5a018d9da50cd8a8a5b366735c971fffdf0b5d3c09689b6b2fa2a1d9 - Sigstore transparency entry: 2243672982
- Sigstore integration time:
-
Permalink:
Himanshu001-cpu/auto-git@f474e18ea6545e297b694c43ae2bc3bfde57c1ca -
Branch / Tag:
refs/tags/v1.0.1 - Owner: https://github.com/Himanshu001-cpu
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-pypi.yml@f474e18ea6545e297b694c43ae2bc3bfde57c1ca -
Trigger Event:
push
-
Statement type:
File details
Details for the file auto_git_cli-1.0.1-py3-none-any.whl.
File metadata
- Download URL: auto_git_cli-1.0.1-py3-none-any.whl
- Upload date:
- Size: 49.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c7b6812be506352f803b2ac3bdf45bd02c0e61c724a257d2ef7d94f44d5cb932
|
|
| MD5 |
75ff262123f6a546d78e53c3206cb299
|
|
| BLAKE2b-256 |
523b1b4552cbf46d4d58f67d9e3d7c0bc80f12a81d7081754a115739082af6fa
|
Provenance
The following attestation bundles were made for auto_git_cli-1.0.1-py3-none-any.whl:
Publisher:
publish-pypi.yml on Himanshu001-cpu/auto-git
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
auto_git_cli-1.0.1-py3-none-any.whl -
Subject digest:
c7b6812be506352f803b2ac3bdf45bd02c0e61c724a257d2ef7d94f44d5cb932 - Sigstore transparency entry: 2243673323
- Sigstore integration time:
-
Permalink:
Himanshu001-cpu/auto-git@f474e18ea6545e297b694c43ae2bc3bfde57c1ca -
Branch / Tag:
refs/tags/v1.0.1 - Owner: https://github.com/Himanshu001-cpu
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-pypi.yml@f474e18ea6545e297b694c43ae2bc3bfde57c1ca -
Trigger Event:
push
-
Statement type: