Skip to content

Instantly share code, notes, and snippets.

@kaznak
Created July 7, 2025 13:30
Show Gist options
  • Select an option

  • Save kaznak/8503e2b59cdd1d9668ad62f4dbd47d29 to your computer and use it in GitHub Desktop.

Select an option

Save kaznak/8503e2b59cdd1d9668ad62f4dbd47d29 to your computer and use it in GitHub Desktop.
Claude Code: Git Commit & Push Command with Auto-Generated Messages
# git commit and push
Commits specified files and pushes to remote repository if configured. Uses Task tool to analyze changes and generate commit message from file contents only.
## Usage
When user specifies files to commit (or no files for all changes), this command will:
1. Use Task tool to analyze the specified files' changes (or all changes if no files specified)
2. Generate commit message based on the changes
3. Add specified files to staging (or all changes if no files specified)
4. Commit with auto-generated message
5. Push to remote if configured
## Implementation
Use Task tool with the following prompt to handle git operations and maintain context separation:
```
You are tasked with performing git commit and push operations. Follow these steps:
1. If file paths are specified: {file_paths}
- Analyze the changes in the specified files only
- Generate commit message based only on changes in these files
- Add only the specified files to git staging area
If no file paths are specified:
- Analyze all changes in the repository (git status, git diff)
- Generate commit message based on all changes
- Add all changes to git staging area (git add .)
2. Check if files exist and have changes
3. Create commit with generated message
4. Check if remote repository is configured
5. If remote exists, push the changes
Requirements:
- Handle both specific files and all changes scenarios
- Generate commit message from actual file changes
- Handle cases where files don't exist or have no changes
- Verify remote repository configuration before pushing
- Use proper git commands and error handling
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment