| name | git-workflow-mastery |
| description | Advanced Git workflows, branching strategies, and commit conventions |
| license | MIT |
| compatibility | git 2.30+ |
| allowed-tools | run_command read_file write_file |
Git Workflow Mastery
Branching Strategies
GitHub Flow (Simple)
main ────●────●────●────●────●────
\ /
feature ●───●───●
Best for: Continuous deployment, small teams
Git Flow (Structured)
main ────●─────────────────●────
\ /
release ●─────●───────●
\ /
develop ────●───●───●───●───●────
\ /
feature ●───●
Best for: Scheduled releases, larger teams
Branch Naming
feature/user-authentication
feature/JIRA-123-add-login
fix/login-redirect-loop
fix/JIRA-456-null-pointer
release/v1.2.0
release/2024-q1
hotfix/security-patch
hotfix/v1.2.1
Commit Messages
Conventional Commits
<type>(<scope>): <description>
[optional body]
[optional footer(s)]
Types
feat:
fix:
docs:
style:
refactor:
perf:
test:
chore:
ci:
revert:
Examples
feat(auth): add OAuth2 login support
fix(api): handle null response from external service
The external payment API occasionally returns null
instead of an error object. Added defensive check.
Fixes
feat(api)!: change response format to JSON:API
BREAKING CHANGE: All API responses now follow JSON:API spec.
Clients need to update their parsers.
Common Operations
Interactive Rebase
git rebase -i HEAD~3
pick abc1234 First commit
squash def5678 Second commit
squash ghi9012 Third commit
Cherry Pick
git cherry-pick abc1234
git cherry-pick abc1234..def5678
Stashing
git stash push -m "WIP: feature login"
git stash list
git stash pop
git stash apply stash@{2}
Undoing Changes
git reset --soft HEAD~1
git reset --hard HEAD~1
git revert abc1234
git checkout -- .
git clean -fd
Advanced Techniques
Bisect (Find Bug Introduction)
git bisect start
git bisect bad
git bisect good v1.0.0
git bisect good
git bisect bad
git bisect reset
Reflog (Recover Lost Commits)
git reflog
git checkout -b recovered-branch abc1234
git reset --hard HEAD@{2}
Worktrees (Multiple Working Directories)
git worktree add ../feature-branch feature/new-ui
git worktree list
git worktree remove ../feature-branch
Hooks
Pre-commit Hook
#!/bin/sh
npm run lint
if [ $? -ne 0 ]; then
echo "Lint failed. Commit aborted."
exit 1
fi
npm test
if [ $? -ne 0 ]; then
echo "Tests failed. Commit aborted."
exit 1
fi
Commit-msg Hook
#!/bin/sh
commit_regex='^(feat|fix|docs|style|refactor|perf|test|chore|ci|revert)(\(.+\))?: .{1,72}'
if ! grep -qE "$commit_regex" "$1"; then
echo "Invalid commit message format."
echo "Use: type(scope): description"
exit 1
fi
Git Aliases
[alias]
co = checkout
br = branch
ci = commit
st = status
lg = log --oneline --graph --decorate
undo = reset --soft HEAD~1
amend = commit --amend --no-edit
wip = !git add -A && git commit -m 'WIP'
sync = !git fetch origin && git rebase origin/main
Best Practices
- Commit early, commit often - Small, focused commits
- Write meaningful commit messages - Explain why, not just what
- Keep main/master deployable - Always in working state
- Review before merging - Use pull requests
- Delete merged branches - Keep repository clean
- Never rewrite shared history - No force push to shared branches
- Use tags for releases - Semantic versioning