| name | git-workflow |
| description | Manage source control effectively with Git including branching strategies, commit conventions, merge conflict resolution, rebasing, and collaboration workflows like GitHub Flow or GitFlow. Use when managing feature branches, creating meaningful commits, resolving merge conflicts, rebasing branches, squashing commits, using interactive rebase, implementing branch naming conventions, following commit message standards, managing pull requests, or collaborating in team environments. |
Git Workflow - Professional Version Control
When to use this skill
- Managing feature branches and branch strategies
- Creating clear, meaningful commit messages
- Resolving merge conflicts effectively
- Rebasing branches to maintain clean history
- Squashing commits before merging
- Using interactive rebase to clean up history
- Implementing branch naming conventions
- Following commit message standards (Conventional Commits)
- Managing pull requests and code reviews
- Collaborating in team Git workflows
- Recovering from Git mistakes (reset, revert, reflog)
- Managing release branches and hotfixes
When to use this skill
- Managing code changes, collaborating with teams, creating branches, handling conflicts, and maintaining clean git history.
- When working on related tasks or features
- During development that requires this expertise
Use when: Managing code changes, collaborating with teams, creating branches, handling conflicts, and maintaining clean git history.
Core Principles
- Commit Often, Push When Stable - Small, focused commits are easier to review and revert
- Main Branch is Sacred - Always deployable, never commit directly
- Clear History Tells a Story - Future developers read commit messages to understand why
- Review Before Sharing - Check
git diff before committing
Essential Commands
Starting Work
git fetch origin
git pull origin main
git checkout -b feature/user-authentication
Making Changes
git status
git diff
git diff --staged
git diff main...HEAD
git add path/to/file
git add path/to/directory
git add -p
git commit -m "feat: add user authentication endpoint
- Implement JWT token generation
- Add password hashing with bcrypt
- Create middleware for auth verification
Closes #123"
Commit Message Format
Use Conventional Commits:
<type>(<scope>): <subject>
<body>
<footer>
Types:
feat: New feature
fix: Bug fix
refactor: Code change that neither fixes a bug nor adds a feature
docs: Documentation only
style: Formatting, missing semicolons, etc.
test: Adding tests
chore: Maintenance tasks
perf: Performance improvement
Examples:
git commit -m "feat: add user avatar upload"
git commit -m "fix: prevent race condition in order processing"
git commit -m "refactor: extract validation logic into separate module"
git commit -m "fix stuff"
git commit -m "WIP"
git commit -m "asdf"
Viewing History
git log --oneline -10
git log -p -2
git log --graph --oneline --all
git blame path/to/file
git log --grep="authentication"
git log --author="alice"
Branching & Merging
git branch
git branch -r
git branch -a
git checkout main
git checkout main
git merge feature/user-auth
git merge --squash feature/user-auth
git branch -d feature/user-auth
git branch -D feature/user-auth
git push origin --delete feature/user-auth
Handling Conflicts
git status
git add path/to/resolved-file
git commit
git merge --abort
Conflict Example:
<<<<<<< HEAD
const apiUrl = 'https://api.prod.example.com';
=======
const apiUrl = 'https://api-v2.example.com';
>>>>>>> feature/update-api
const apiUrl = 'https://api-v2.example.com';
Undoing Changes
git checkout -- path/to/file
git reset HEAD path/to/file
git reset --soft HEAD~1
git reset --hard HEAD~1
git revert abc123
git commit --amend
git commit --amend --no-edit
Stashing
git stash
git stash save "WIP: working on user profile"
git stash list
git stash apply
git stash pop
git stash apply stash@{2}
git stash drop stash@{0}
git stash clear
Rebasing
git checkout feature/user-auth
git rebase main
git rebase -i HEAD~5
git rebase --abort
git rebase --continue
⚠️ Never rebase commits that have been pushed to shared branches!
Cherry-Picking
git cherry-pick abc123
git cherry-pick abc123 def456
git cherry-pick -n abc123
Workflow Patterns
Feature Branch Workflow
git checkout main
git pull origin main
git checkout -b feature/new-feature
git add .
git commit -m "feat: implement new feature"
git fetch origin
git rebase origin/main
git push origin feature/new-feature
git checkout main
git pull origin main
git branch -d feature/new-feature
Gitflow Workflow
git checkout develop
git checkout -b feature/awesome-feature
git checkout develop
git merge --no-ff feature/awesome-feature
git branch -d feature/awesome-feature
git checkout develop
git checkout -b release/1.2.0
git checkout main
git merge --no-ff release/1.2.0
git tag -a v1.2.0 -m "Release 1.2.0"
git checkout main
git checkout -b hotfix/critical-bug
git checkout main
git merge --no-ff hotfix/critical-bug
git checkout develop
git merge --no-ff hotfix/critical-bug
git tag -a v1.2.1 -m "Hotfix 1.2.1"
Trunk-Based Development
git checkout main
git pull origin main
git checkout -b feature/quick-change
git commit -am "feat: add button"
git push origin feature/quick-change
Git Configuration
Essential Config
git config --global user.name "Your Name"
git config --global user.email "you@example.com"
git config --global core.editor "code --wait"
git config --global init.defaultBranch main
git config --global alias.co checkout
git config --global alias.br branch
git config --global alias.ci commit
git config --global alias.st status
git config --global alias.unstage 'reset HEAD --'
git config --global alias.last 'log -1 HEAD'
git config --global alias.visual 'log --graph --oneline --all'
git config --global help.autocorrect 20
git config --global color.ui auto
git config --global push.default current
git config --global pull.rebase true
.gitignore
git config --global core.excludesfile ~/.gitignore_global
.DS_Store
Thumbs.db
.vscode/
.idea/
*.swp
*.swo
*~
node_modules/
venv/
vendor/
dist/
build/
*.pyc
*.class
.env
.env.local
secrets.yml
*.pem
*.log
logs/
Advanced Techniques
Git Worktrees
git worktree add ../project-feature2 feature/feature2
cd ../project-feature2
git worktree list
git worktree remove ../project-feature2
Bisect (Find Breaking Commit)
git bisect start
git bisect bad
git bisect good v1.0.0
git bisect good
git bisect bad
Reflog (Safety Net)
git reflog
git checkout abc123
git reset --hard HEAD@{2}
Best Practices
✅ Do
- Write clear, descriptive commit messages
- Commit logical units of change
- Review diffs before committing (
git diff --staged)
- Pull before pushing
- Keep commits small and focused
- Use branches for all changes
- Delete branches after merging
❌ Don't
- Commit secrets or credentials
- Commit generated files (build artifacts)
- Commit directly to main
- Rewrite history on shared branches
- Create massive commits with unrelated changes
- Use vague commit messages
- Push broken code
Troubleshooting
Common Issues
"Detached HEAD":
git checkout -b new-branch-name
"Merge conflict in large file":
git checkout --theirs path/to/file
git checkout --ours path/to/file
git add path/to/file
"Accidentally committed to main":
git branch feature/accidental
git reset --hard origin/main
git checkout feature/accidental
"Pushed sensitive data":
git push --force-with-lease
Resources
Remember: Git is a time machine for your code. Use it to create checkpoints, explore alternative solutions safely, and maintain a clear history of why changes were made.