Generating commit message with AI...
Generated commit message:
feat(auto): allow customizable autocommit rules via .autocommit.md
Do you want to commit with this message? (y/n/r=retry):- Executes all standard Git commands
- Provides cleaner success messages
- Passes all arguments to the underlying Git command
- Fall-through behavior for any Git command not explicitly listed
- AI-powered autocommit feature to generate commit messages following Conventional Commits format
- Cobra CLI Framework: Professional command-line interface with automatic help generation
- Retry functionality: Regenerate commit messages until you get one you like
- Batch commit mode: Select multiple files and commit them together with one unified message
- Individual file selection: Choose specific files from directories instead of entire folders
- Customizable commit message rules via .autocommit.md file
- Flexible configuration options for OpenAI API key
- API key validation and troubleshooting
# Build the application (now using Cobra CLI framework)
go build -o gg.exeNote: The application now uses the Cobra CLI framework for better command structure and help system.
For convenience, you can add the directory containing gg.exe to your system PATH to run it from any location:
On Windows:
- Open System Properties → Advanced → Environment Variables
- Edit the PATH variable and add the directory containing gg.exe
- Open a new command prompt for the changes to take effect
On Linux/macOS:
export PATH="$PATH:/path/to/directory/containing/gg"
The gg config command helps you manage your OpenAI API key and other settings:
gg config # View current configuration status
gg config reset # Reset and update your API key
When viewing your configuration, the app will show all locations where it looks for your API key, whether each exists, and whether the keys are valid or invalid.
If your API key is invalid or expired, you'll receive a specific error message when using features that require the OpenAI API. You can:
- Run
gg config resetto update your API key - The app will prompt you to enter a new key and choose where to save it
- The new key will be validated immediately to ensure it works
The application will look for your OpenAI API key in several locations, in the following order:
- System environment variable (
OPENAI_API_KEY) .envfile in the current working directory- Config file in your home directory (
~/.gg/config.json) .envfile or config in the same directory as the executable- If no API key is found, it will prompt you to enter one interactively
Set the OPENAI_API_KEY environment variable:
On Windows:
set OPENAI_API_KEY=your_api_key_here
On Linux/macOS:
export OPENAI_API_KEY=your_api_key_here
Create a .env file in your project directory:
OPENAI_API_KEY=your_openai_api_key_here
The recommended approach is to store your API key in your user home directory:
~/.gg/config.json
With content:
{
"openai_api_key": "your_api_key_here"
}This file will be created automatically if you run the autocommit command and choose to save the API key to your home directory when prompted.
You can customize the commit message format by creating or editing the .autocommit.md file. This file contains the rules that will be sent to the AI when generating commit messages.
The application follows this hierarchy for finding autocommit rules:
-
Project root
.autocommit.md(highest priority)- Create this file in your project's root directory to override default rules
- This file is listed in
.gitignore, so it won't be committed to your repository - Perfect for project-specific commit message conventions
-
Default
.autocommit.md(fallback)- Located in the same directory as the
ggexecutable - Used when no project-specific rules are found
- Provides sensible defaults for all users
- Located in the same directory as the
-
Built-in default (lowest priority)
- Used only if no
.autocommit.mdfiles are found - Follows the Conventional Commits format
- Used only if no
Example .autocommit.md content:
# Autocommit Rules
Please follow the Conventional Commits 1.0.0 specification for the commit message.
<type>[optional scope]: <description>
[optional body]
[optional footer(s)]
Common types include:
- feat: A new feature
- fix: A bug fix
- docs: Documentation changes
- style: Code style changes (formatting, etc.)
- refactor: Code refactoring
- test: Testing changes
- chore: Maintenance tasksgg --help # Show all available commands
gg <command> --help # Show help for specific command
gg autocommit --help # Show help for autocommit
gg config --help # Show help for config managementgg init # Initialize a new repository
gg add <file> # Add file to staging area
gg commit -m "commit message" # Commit staged changes
gg log # View commit history
gg status # Check status of working directory
gg diff # View differences
gg branch # List, create, or delete branches
gg checkout <branch> # Switch branches
gg push # Push to remote repository
gg pull # Pull from remote repositorygg autocommit # Auto-add all changes and generate AI commit message
gg ac # Alias for autocommit
gg autocommit-per-file # Interactive per-file commits with AI messages
gg acpf # Alias for autocommit-per-filegg config # Show current configuration
gg config reset # Reset and update API key
gg last # Show detailed information about the last commitGitGud passes all arguments directly to Git, so any valid Git command and options will work. The Cobra framework provides comprehensive help for all commands.
The last command provides detailed information about the most recent commit:
./gg last
This will show:
- Commit hash
- Author name
- Commit date
- Commit message
- Detailed changes (files modified, insertions, deletions)
The autocommit command (or its shorter alias ac):
- Automatically detects all changes in your repository
- Includes the current branch name for context-aware commit messages
- Provides context from the last commit (hash, author, date, and message)
- Sends the diff to OpenAI to generate a meaningful commit message following the Conventional Commits format
- Shows you the suggested commit message with retry options
- NEW: Press
rorretryto regenerate the message until you're satisfied - If you confirm, stages all changes and commits them with the AI-generated message
Important: You can customize the commit message format by creating or editing the .autocommit.md file. Since this file is in .gitignore, you'll need to create it in each repository where you use this tool.
The AI assistant takes into account:
- The current branch name (e.g.,
feature/user-auth,fix/login-bug) - Last commit information (e.g., "Last commit: a1b2c3d by John Doe on Mon Jan 1 12:00:00 2024 - feat: initial implementation")
- The changes in your working directory
- Your custom commit message rules from
.autocommit.md
This helps generate more contextually relevant commit messages that align with your branch's purpose and development history.
Example:
./gg autocommit
# or
./gg ac
The autocommit command generates commit messages following the Conventional Commits specification:
<type>[optional scope]: <description>
[optional body]
[optional footer(s)]
Common types include:
feat: A new featurefix: A bug fixdocs: Documentation changesstyle: Changes that don't affect code functionality (formatting, etc.)refactor: Code changes that neither fix bugs nor add features
Both autocommit and autocommit-per-file now support retry functionality. If you don't like the AI-generated commit message, you can regenerate it without starting over.
When prompted with a commit message, you now have these options:
yoryes- Commit with the current messagenorno- Cancel/skip the commitrorretry- Generate a new message 🔄exit- Exit the program (acpf only)
gg autocommit
Generated commit message:
fix: update configuration settings
Do you want to commit with this message? (y/n/r=retry): r
Regenerating commit message...
Generated commit message:
feat(config): implement dynamic configuration management
Do you want to commit with this message? (y/n/r=retry): y
Changes committed successfully!- AI Variability: Each generation can produce different results
- Better Quality: Keep trying until you get a message you like
- No Wasted Work: Same changes, just different AI interpretation
- Learn Patterns: See how AI interprets your changes differently
The autocommit-per-file (or acpf) feature allows you to commit files individually or in batches with AI-generated commit messages. This feature has been significantly enhanced with:
- Individual file selection: Choose specific files instead of entire directories
- Batch commit mode: Select multiple files and commit them together with one unified message
- Retry functionality: Regenerate commit messages until you're satisfied
- Improved file listing: See individual files instead of directory names
gg autocommit-per-file
# or
gg acpf- List Changed Files: The tool displays all individual files with changes (no more directory grouping!)
- Interactive File Selection: You can select which files to commit using arrow key navigation:
- Use ↑/↓ arrow keys to navigate
- Press Enter to select an option
- Select individual files one by one
- Select all remaining files at once
- Proceed with currently selected files
- Exit at any time
- Batch Processing: Selected files are processed together:
- NEW: All selected files are committed together as one batch
- Shows combined diff for all selected files
- Asks for context for the entire batch (not per file)
- Generates one unified AI-powered commit message
- NEW: Option to retry message generation with
rorretry - Commits all selected files with one message
- Loop Process: After processing the batch, you can continue with remaining files or exit
- ✅ Interactive file selection with arrow key navigation
- ✅ NEW: Individual file listing (no more directory grouping)
- ✅ NEW: Batch commit mode - commit multiple files with one message
- ✅ NEW: Retry functionality - regenerate messages until satisfied
- ✅ AI-generated commit messages for file batches
- ✅ Custom context for each batch
- ✅ Loop through the process multiple times
- ✅ Exit at any time using the menu
- ✅ Handles new, modified, staged, and renamed files
- ✅ Uses your existing autocommit rules from
.autocommit.md - ✅ Beautiful terminal UI with colors and icons
=== Autocommit Per File ===
This will help you commit files individually with AI-generated commit messages.
Use arrow keys to navigate and select files. You can select multiple files interactively.
=== Interactive File Selection ===
Select files one by one. You can repeat this process until you're done.
Files selected so far: 0
Remaining files: 3
Choose an action:
▶ ✅ Proceed with selected files
📄 Select all remaining files
❌ Exit
📄 main.go
📄 README.md
📄 test_feature.txt
[User navigates with arrows and selects main.go, then test_feature.txt]
--- Processing 2 selected file(s) ---
- main.go
- test_feature.txt
Enter additional context for these 2 file(s) (press Enter to skip): Added new autocommit per file feature with batch processing
Generating commit message for 2 file(s)...
Generated commit message for batch:
feat: add autocommit per file functionality with batch processing
Do you want to commit these files with this message? (y/n/r=retry/exit): r
Regenerating commit message for 2 file(s)...
Generated commit message for batch:
feat(autocommit): implement batch processing for selective file commits
Do you want to commit these files with this message? (y/n/r=retry/exit): y
Successfully committed 2 file(s) in one commit
--- Processing complete ---
Continue with remaining files? (y/n): y
- OpenAI API key configured (same as regular autocommit)
- Git repository initialized
- Changed files to commit
- NEW: Use the retry feature (
r) to get better commit messages - Use specific context to get better commit messages for the batch
- You can skip batches by answering 'n' when asked to commit
- The feature respects your
.autocommit.mdrules - NEW: Selected files are committed together in one commit (not separately)
- Use arrow keys for easy navigation - no need to type numbers
- You can select files incrementally and see your progress
- The interface shows clear visual feedback with colors and icons
- NEW: Individual files are shown instead of directory names (e.g.,
internal/config/config.goinstead ofinternal/)
Custom context is a powerful feature in GitGud that helps you create more meaningful commit messages. It allows you to provide additional information about your changes, which the AI assistant uses along with your branch name and last commit details to generate better commit messages.
-
Setup Your Rules Create a
.autocommit.mdfile in your project root:Please follow the Conventional Commits format: <type>(<scope>): <#time> <description> - #time: The time spent on the task (use the #time tag in the custom context to add the time spent on the task) Example: feat(auth): #1h add login form Types: - feat: A new feature - fix: A bug fix - docs: Documentation changes
-
Run Autocommit
gg autocommit
-
Add Your Context When prompted, enter your time spent:
#1h -
Review Generated Message The AI will create a commit message using your context:
feat(auth): #1h add login form
GitGud combines three sources of information to generate your commit message:
-
Your Custom Context
- Time spent on the task
- Any additional tags you provide
-
Last Commit Information
- Commit hash
- Author name
- Commit date
- Previous commit message
-
Branch Name
feature/user-auth→ Authentication-related changesfix/login-bug→ Bug fixes in logindocs/api-update→ Documentation updates
-
Time Tracking
# .autocommit.md configuration Please follow the Conventional Commits format: <type>(<scope>): <#time> <description> - #time: The time spent on the task (use the #time tag in the custom context) Example: feat(auth): #1h add login form Types: - feat: A new feature - fix: A bug fix - docs: Documentation changes
# Create feature branch gg checkout -b feature/user-auth # Make changes to auth system... # Commit with time context gg autocommit # Enter: #2h # Result: feat(auth): #2h implement OAuth2 authentication
-
Multiple Context Tags
# .autocommit.md configuration Please follow the Conventional Commits format: <type>(<scope>): <#time> <description> <#complexity> <#impact> - #time: Time spent on the task - #complexity: Complexity level (low/medium/high) - #impact: Impact level (low/medium/high/critical) Example: fix(auth): #1h resolve validation #complexity:high #impact:critical Types: - feat: A new feature - fix: A bug fix - docs: Documentation changes
# Create fix branch gg checkout -b fix/login-validation # Fix validation issues... # Commit with multiple context tags gg autocommit # Enter: #1h #complexity:high #impact:critical # Result: fix(auth): #1h resolve login validation issues #complexity:high #impact:critical
-
Feature Branch
# .autocommit.md configuration Please follow the Conventional Commits format: <type>(<scope>): <#time> <description> - #time: The time spent on the task - Scope should match branch name prefix (feature/fix/docs) Example: feat(payment): #2h add payment processing Types: - feat: A new feature - fix: A bug fix - docs: Documentation changes
# Branch name indicates feature type gg checkout -b feature/payment-gateway # Implement payment system... # Commit with time context gg autocommit # Enter: #4h # Result: feat(payment): #4h implement Stripe payment integration
-
Bug Fix Branch
# .autocommit.md configuration Please follow the Conventional Commits format: <type>(<scope>): <#time> <description> - #time: The time spent on the task - Scope should match branch name prefix (feature/fix/docs) Example: fix(api): #1h resolve timeout issues Types: - feat: A new feature - fix: A bug fix - docs: Documentation changes
# Branch name indicates bug fix gg checkout -b fix/api-timeout # Fix timeout issues... # Commit with time context gg autocommit # Enter: #1h # Result: fix(api): #1h resolve request timeout issues
-
Related Feature
# .autocommit.md configuration Please follow the Conventional Commits format: <type>(<scope>): <#time> <description> - #time: The time spent on the task - Consider last commit context for related changes Example: feat(profile): #2h add user settings Types: - feat: A new feature - fix: A bug fix - docs: Documentation changes
# Previous commit: feat(auth): #2h add login form # Current branch: feature/user-profile # Add profile functionality... # Commit with time context gg autocommit # Enter: #3h # Result: feat(profile): #3h implement user profile management
-
Bug Fix Follow-up
# .autocommit.md configuration Please follow the Conventional Commits format: <type>(<scope>): <#time> <description> - #time: The time spent on the task - Consider last commit context for related fixes Example: fix(auth): #1h handle edge cases Types: - feat: A new feature - fix: A bug fix - docs: Documentation changes
# Previous commit: fix(auth): #1h resolve login validation # Current branch: fix/auth-edge-cases # Fix additional edge cases... # Commit with time context gg autocommit # Enter: #2h # Result: fix(auth): #2h handle additional login edge cases
-
Feature with Related Fix
# .autocommit.md configuration Please follow the Conventional Commits format: <type>(<scope>): <branch-name> <#time> <description> - #time: The time spent on the task - branch-name: The name of the branch (will be the card name from JIRA) - Consider both branch name and last commit context Example: fix(payment): #1h improve validation Types: - feat: JIRA-1234: A new feature - fix: JIRA-1235: A bug fix - docs: JIRA-1236: Documentation changes
# Previous commit: feat(payment): #4h add payment processing # Current branch: JIRA-1235 # Fix payment validation... # Commit with time context gg autocommit # Enter: #1h # Result: fix(payment): JIRA-1235 #1h improve payment validation rules
-
Documentation Update
# .autocommit.md configuration Please follow the Conventional Commits format: <type>(<scope>): <#time> <description> - #time: The time spent on the task - Consider last commit for related documentation Example: docs(api): #1h update endpoint docs Types: - feat: A new feature - fix: A bug fix - docs: Documentation changes
# Previous commit: feat(api): #3h add new endpoints # Current branch: docs/api-update # Update API documentation... # Commit with time context gg autocommit # Enter: #2h # Result: docs(api): #2h document new API endpoints
-
Refactoring with Context
# .autocommit.md configuration Please follow the Conventional Commits format: <type>(<scope>): <#time> <description> - #time: The time spent on the task - Consider last commit for related refactoring Example: refactor(ui): #2h optimize components Types: - feat: A new feature - fix: A bug fix - docs: Documentation changes - refactor: Code restructuring
# Previous commit: feat(ui): #5h implement dashboard # Current branch: refactor/optimize-ui # Optimize UI components... # Commit with time context gg autocommit # Enter: #3h # Result: refactor(ui): #3h optimize dashboard performance
If your custom context isn't working as expected:
-
Check File Format
- Ensure your
.autocommit.mdfile is in the correct location - Verify the file format matches the example
- Ensure your
-
Verify Tag Usage
- Make sure you're using the correct tag format
- Check that tags are properly formatted (e.g.,
#1hnot1h)
-
Check Input
- Confirm your custom context is entered correctly
- Ensure there are no extra spaces or special characters
-
Review Output
- Check if the AI is following your custom rules
- Verify the generated commit message format