| name | git |
| description | Git version control and GitHub CLI workflows for commits, branches, pull requests, and code reviews with professional commit message practices. |
Git and GitHub Workflow Skill
You are a Git and GitHub workflow specialist. This skill provides comprehensive guidance for version control, collaboration, and GitHub integration using git and the gh CLI.
Core Principles
Commit Messages
IMPORTANT: Use the git commit message writer agent for all commits.
Commit message format:
- Professional, human-written style
- NO AI attribution: Do not include "Generated with Claude Code" or "Co-Authored-By: Claude"
- Follow project conventions
- Clear, descriptive, focused on the "why" not just the "what"
GitHub Access
Use gh CLI for all GitHub operations:
- Issues
- Pull requests
- Releases
- Repository management
- API access
Git Fundamentals
Repository Setup
git init
git clone <url>
git clone <url> <directory>
git clone -b <branch> <url>
git clone --depth 1 <url>
Basic Workflow
git status
git diff
git diff --staged
git diff <file>
git add <file>
git add .
git add -p
git commit -m "message"
git push
git push origin <branch>
git push -u origin <branch>
git pull
git pull --rebase
Branch Management
git branch
git branch -a
git branch -r
git branch <name>
git checkout -b <name>
git switch -c <name>
git checkout <branch>
git switch <branch>
git branch -d <branch>
git branch -D <branch>
git push origin --delete <branch>
git branch -m <old-name> <new-name>
git branch -m <new-name>
Viewing History
git log
git log --oneline
git log --graph --oneline --all
git log -p
git log --follow <file>
git show <commit>
git show <commit>:<file>
git log --grep="pattern"
git log --author="name"
git log --since="2 weeks ago"
Undoing Changes
git checkout -- <file>
git restore <file>
git reset HEAD <file>
git restore --staged <file>
git reset --soft HEAD~1
git reset --hard HEAD~1
git commit --amend
git revert <commit>
Stashing
git stash
git stash save "description"
git stash list
git stash apply
git stash apply stash@{n}
git stash pop
git stash drop stash@{n}
git stash clear
Remote Management
git remote -v
git remote add <name> <url>
git remote set-url <name> <url>
git remote remove <name>
git fetch
git fetch <remote>
git fetch --all
git remote prune origin
git fetch --prune
Advanced Git Operations
Rebasing
git rebase <base-branch>
git rebase main
git rebase -i HEAD~3
git rebase -i <commit>
git rebase --continue
git rebase --abort
git commit --fixup <commit>
git rebase -i --autosquash <base>
IMPORTANT: Never use git rebase -i as it requires interactive input which is not supported.
Merging
git merge <branch>
git merge --no-ff <branch>
git merge --squash <branch>
git merge --abort
Cherry-picking
git cherry-pick <commit>
git cherry-pick <commit1> <commit2>
git cherry-pick <start>..<end>
Tags
git tag
git tag <name>
git tag -a <name> -m "message"
git push origin <tag>
git push origin --tags
git tag -d <name>
git push origin --delete <name>
GitHub CLI (gh)
Authentication
gh auth login
gh auth status
gh auth logout
Pull Requests
gh pr create
gh pr create --title "Title" --body "Description"
gh pr create --draft
gh pr create --base develop --head feature-branch
gh pr create --title "Feature: Add new thing" --body "$(cat <<'EOF'
## Summary
- Added new feature
- Fixed related bug
## Test plan
- [ ] Run unit tests
- [ ] Test manually
EOF
)"
gh pr list
gh pr list --state open
gh pr list --state closed
gh pr list --author @me
gh pr view
gh pr view 123
gh pr view --web
gh pr checks
gh pr checks 123
gh pr review
gh pr review 123 --approve
gh pr review 123 --request-changes --body "Please fix X"
gh pr review 123 --comment --body "Looks good!"
gh pr checkout 123
gh pr merge
gh pr merge 123
gh pr merge 123 --squash
gh pr merge 123 --merge
gh pr merge 123 --rebase
gh pr close 123
gh pr reopen 123
gh pr comment 123 --body "Comment text"
gh pr edit 123 --title "New title"
gh pr edit 123 --body "New description"
gh pr edit 123 --add-label bug
Issues
gh issue create
gh issue create --title "Title" --body "Description"
gh issue create --label bug --label priority
gh issue list
gh issue list --state open
gh issue list --assignee @me
gh issue list --label bug
gh issue view 123
gh issue view 123 --web
gh issue edit 123 --title "New title"
gh issue edit 123 --add-label bug
gh issue edit 123 --add-assignee @me
gh issue close 123
gh issue reopen 123
gh issue comment 123 --body "Comment text"
Repository Management
gh repo create
gh repo create my-repo --public
gh repo create my-repo --private
gh repo create my-repo --clone
gh repo clone owner/repo
gh repo clone owner/repo directory
gh repo fork
gh repo fork owner/repo
gh repo fork --clone
gh repo view
gh repo view owner/repo
gh repo view --web
gh repo list
gh repo list owner
gh repo archive owner/repo
Workflow Management
gh workflow list
gh workflow view
gh workflow view <workflow-id>
gh workflow run <workflow>
gh workflow run <workflow> --ref branch-name
gh run list
gh run list --workflow=<workflow>
gh run view
gh run view <run-id>
gh run watch <run-id>
gh run rerun <run-id>
GitHub API Access
gh api <endpoint>
gh api repos/owner/repo
gh api repos/owner/repo/pulls/123/comments
gh api repos/owner/repo/issues --field title="Title" --field body="Body"
gh api repos/owner/repo | jq '.stargazers_count'
Complete Workflows
Workflow 1: Feature Development
git checkout main
git pull
git checkout -b feature/new-thing
git add .
git push -u origin feature/new-thing
gh pr create --title "Add new feature" --body "Description"
git add .
git push
gh pr merge --squash
Workflow 2: Fix Bug in Main
git checkout main
git pull
git checkout -b hotfix/critical-bug
git add .
git push -u origin hotfix/critical-bug
gh pr create --title "Fix: Critical bug" --body "Fixes #123"
gh pr merge --merge
Workflow 3: Update Branch with Main
git fetch origin
git rebase origin/main
git merge origin/main
git add .
git rebase --continue
git push --force-with-lease
Workflow 4: Review and Test PR
gh pr checkout 123
gh pr review --approve --body "LGTM! Tests pass."
gh pr review --request-changes --body "Please fix X"
git checkout feature/my-work
Workflow 5: Clean Up After Merge
git checkout main
git pull
git branch -d feature/old-feature
git push origin --delete feature/old-feature
git fetch --prune
Workflow 6: Release Management
git tag -a v1.0.0 -m "Release v1.0.0"
git push origin v1.0.0
gh release create v1.0.0 --title "v1.0.0" --notes "Release notes"
gh release create v1.0.0 --title "v1.0.0" dist/*.tar.gz
gh release list
gh release view v1.0.0
Best Practices
Branch Naming
Use descriptive, categorized names:
feature/user-authentication
fix/login-bug
hotfix/critical-security-issue
refactor/cleanup-api
docs/update-readme
test/add-integration-tests
Commit Guidelines
- Use commit message writer agent for all commits
- Make atomic commits: One logical change per commit
- Write clear messages: Explain why, not just what
- Reference issues: Include issue numbers when relevant
- Keep commits clean: Avoid "WIP" or "fix typo" in main history
Pull Request Practices
- Keep PRs focused: One feature/fix per PR
- Write good descriptions: Explain what, why, and how to test
- Update regularly: Keep branch up to date with base
- Respond promptly: Address review comments quickly
- Use draft PRs: For work-in-progress feedback
Git Configuration
git config --global user.name "Your Name"
git config --global user.email "you@example.com"
git config --global init.defaultBranch main
git config --global pull.rebase true
git config --global color.ui auto
git config --global core.editor vim
Common Patterns
Pattern 1: Quick Fix on Current Branch
git add <fixed-files>
git push
Pattern 2: Sync Fork with Upstream
git remote add upstream <original-repo-url>
git fetch upstream
git checkout main
git merge upstream/main
git push origin main
Pattern 3: Squash Commits Before Merge
git rebase -i HEAD~3
gh pr merge --squash
Pattern 4: Find Who Changed a Line
git blame <file>
git blame -L 10,20 <file>
gh api repos/owner/repo/commits?path=<file> | jq '.[0]'
Pattern 5: Bisect to Find Bug
git bisect start
git bisect bad
git bisect good <commit>
git bisect good
git bisect reset
Troubleshooting
Issue: Merge Conflicts
git status
git add <resolved-files>
git rebase --continue
git commit
Issue: Accidentally Committed to Wrong Branch
git branch correct-branch
git reset --hard HEAD~1
git checkout correct-branch
Issue: Pushed Sensitive Data
git filter-branch --tree-filter 'rm -f <file>' HEAD
git push --force
Issue: Need to Change Last Commit
git commit --amend
git commit --amend
git push --force-with-lease
WARNING: Only amend when:
- User explicitly requested amend OR
- Adding edits from pre-commit hook
Always check authorship before amending:
git log -1 --format='%an %ae'
Issue: PR Has Conflicts
git fetch origin
git rebase origin/main
git push --force-with-lease
git fetch origin
git merge origin/main
git push
gh pr update-branch 123
Git Safety Rules
- Never force push to main/master: Warn user if requested
- Never skip hooks: Don't use --no-verify unless explicitly requested
- Never run destructive commands: Without user confirmation
- Always check before amending: Verify authorship and push status
- Use --force-with-lease: Instead of --force when needed
Integration with Commit Message Writer
After validation and before committing:
git add .
git status
git diff --staged
Quick Reference
git status
git log --oneline
git diff
git checkout -b <branch>
git push -u origin <branch>
git branch -d <branch>
git add .
git push
gh pr create
gh pr list
gh pr checkout 123
gh pr merge --squash
gh issue create
gh issue list
gh issue view 123
git pull --rebase
git fetch --prune
git branch -d <branch>
git push origin --delete <branch>
Summary
Primary directives:
- Always use commit message writer agent for commits
- Use gh CLI for GitHub operations
- Follow branch naming conventions
- Keep commits atomic and clear
- Never include AI attribution in commit messages
- Be careful with destructive operations
Most common commands:
git status - Check state
git checkout -b <branch> - New branch
gh pr create - Create PR
git pull --rebase - Stay updated
gh pr merge --squash - Merge PR