| name | scm |
| description | Guide for effective source control management with Git following modern best practices. Covers branching strategies, commit hygiene, PR workflows, and team collaboration patterns. Triggers on "git", "source control", "version control", "branching", "merge", "rebase", "git workflow", "pull request", "commit message", "git history", "git conflict", "git stash", "git cherry-pick", "git bisect", "git blame", "git log", "git diff", "git reset", "git checkout", "git switch", "git restore", "git tag", "git remote", "git fetch", "git pull", "git push", "git branch", "conventional commits", "squash", "force push", "git hooks", "pre-commit", "commit-msg", "gitignore", "git submodule", "git worktree", "feature branch", "trunk based", "git flow", "github flow", "commit and push", "commit changes", "push changes", "push to remote", "commit this", "commit these", "make a commit", "create commit". PROACTIVE: MUST invoke when performing complex Git operations or setting up workflows. |
| allowed-tools | Read, Write, Edit, Bash, Glob, Grep |
ABOUTME: Source control management skill for Git best practices and workflows
ABOUTME: Covers branching, commits, PRs, conflict resolution, and team collaboration
Source Control Management (SCM) Skill
Quick Reference
| Principle | Rule |
|---|
| Atomic Commits | One logical change per commit |
| Conventional Commits | type(scope): description format |
| Clean History | Rebase before merge for linear history |
| Branch Naming | type/ticket-description format |
| PR Size | < 400 lines of code changes |
| Never Force Push | To shared branches (main, develop) |
๐ RESUMED SESSION CHECKPOINT
When a session is resumed from context compaction, verify Git state:
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ SESSION RESUMED - SCM SKILL VERIFICATION โ
โ โ
โ Before continuing Git operations: โ
โ โ
โ 1. Was I in the middle of Git operations? โ
โ โ Check summary for "commit", "merge", "rebase" โ
โ โ
โ 2. Current repository state: โ
โ โ Run: git status โ
โ โ Run: git log --oneline -5 โ
โ โ Run: git branch -vv โ
โ โ
โ 3. Pending operations: โ
โ โ Check for: .git/MERGE_HEAD (merge in progress) โ
โ โ Check for: .git/rebase-merge (rebase in progress) โ
โ โ Check for: .git/CHERRY_PICK_HEAD (cherry-pick) โ
โ โ
โ If operation was interrupted: โ
โ โ Complete or abort the pending operation โ
โ โ Verify working directory is clean โ
โ โ Ensure no uncommitted changes are lost โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
Branching Strategies
Git Flow (Traditional)
main โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ โ โ
โ merge โ merge โ
โ โ โ
develop โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ โ โ โ
โ โ โ โ
feature/xyz โโโโโโโโโ feature/abc โโโโโโ
Use when:
- Scheduled releases
- Multiple versions in production
- Formal QA process
Branches:
main: Production code
develop: Integration branch
feature/*: New features
release/*: Release preparation
hotfix/*: Emergency fixes
GitHub Flow (Simplified)
main โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ โ โ โ
โ โ โ โ
feature โโโโโโโโโโโ fix โโโโโโโโโโโ
Use when:
- Continuous deployment
- Small teams
- Rapid iteration
Branches:
main: Always deployable
feature/*, fix/*, chore/*: Short-lived branches
Trunk-Based Development
main โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ โ โ โ โ
โ โ โ โ โ
โโโโโโโดโโโโโโดโโโโโโดโโโโโโดโโ Small, frequent commits
Use when:
- Mature CI/CD pipeline
- Feature flags available
- High-trust team
Branch Naming Convention
<type>/<ticket>-<brief-description>
Examples:
- feature/PROJ-123-user-authentication
- fix/PROJ-456-login-timeout
- chore/PROJ-789-update-dependencies
- docs/PROJ-012-api-documentation
- refactor/PROJ-345-extract-service
| Type | Purpose |
|---|
feature/ | New functionality |
fix/ | Bug fixes |
chore/ | Maintenance tasks |
docs/ | Documentation only |
refactor/ | Code restructuring |
test/ | Test additions |
hotfix/ | Emergency production fixes |
Conventional Commits
Format
<type>(<scope>): <description>
[optional body]
[optional footer(s)]
Types
| Type | Description | Triggers |
|---|
feat | New feature | Minor version bump |
fix | Bug fix | Patch version bump |
docs | Documentation only | No version bump |
style | Formatting, no code change | No version bump |
refactor | Code change, no feature/fix | No version bump |
test | Adding/fixing tests | No version bump |
chore | Build process, tooling | No version bump |
perf | Performance improvement | Patch version bump |
ci | CI configuration | No version bump |
build | Build system changes | No version bump |
revert | Revert previous commit | Varies |
Examples
feat(auth): add OAuth2 login support
fix(api): handle null response from payment gateway
The payment gateway occasionally returns null instead of
an error object. Added null check before processing.
Fixes
feat(api)!: change user endpoint response format
BREAKING CHANGE: The /api/users endpoint now returns
a paginated response object instead of an array.
fix(security): upgrade vulnerable dependency
Reviewed-by: John Doe
Refs: CVE-2024-12345
Commit Best Practices
Atomic Commits
Each commit should:
- Represent ONE logical change
- Be independently revertable
- Pass all tests
- Have a clear, descriptive message
git add .
git commit -m "various fixes and updates"
git add src/auth/
git commit -m "feat(auth): implement password reset flow"
git add tests/auth/
git commit -m "test(auth): add password reset tests"
git add package.json package-lock.json
git commit -m "chore(deps): update authentication libraries"
Interactive Staging
git add -p
git add -i
Commit Message Guidelines
Subject line:
- Max 50 characters
- Imperative mood ("add" not "added")
- No period at end
- Capitalize first word after type
Body (optional):
- Wrap at 72 characters
- Explain WHAT and WHY, not HOW
- Reference issues/tickets
git commit
git commit -m "fix(api): correct rate limit calculation"
Merging vs Rebasing
When to Merge
git checkout main
git merge feature/user-auth --no-ff
Use merge when:
- Preserving feature branch history is important
- Working with public/shared branches
- Team prefers merge commits
When to Rebase
git checkout feature/user-auth
git rebase main
Use rebase when:
- Cleaning up local commits before PR
- Updating feature branch with main
- Maintaining linear project history
Interactive Rebase for Cleanup
git rebase -i HEAD~5
pick abc1234 feat: add user model
squash def5678 fix: typo in user model
pick ghi9012 feat: add login endpoint
reword jkl3456 feat: add logout endpoint
drop mno7890 WIP: debugging
Pull Request Workflow
Before Creating PR
git fetch origin
git rebase origin/main
npm test
npm run lint
git diff origin/main...HEAD
git log origin/main..HEAD --oneline
PR Size Guidelines
| Size | Lines Changed | Review Time |
|---|
| XS | < 50 | Minutes |
| S | 50-200 | < 30 min |
| M | 200-400 | < 1 hour |
| L | 400-800 | Hours |
| XL | > 800 | Split required |
PR Description Template
## Summary
Brief description of changes (1-3 bullet points)
## Changes
- Added X feature
- Modified Y component
- Fixed Z bug
## Testing
- [ ] Unit tests pass
- [ ] Integration tests pass
- [ ] Manual testing completed
## Screenshots (if UI changes)
[Before/After screenshots]
## Related Issues
Closes #123
Refs #456
Conflict Resolution
Understanding Conflicts
<<<<<<< HEAD (current branch)
const timeout = 5000;
=======
const timeout = 10000;
>>>>>>> feature-branch (incoming changes)
Resolution Strategies
git checkout --ours path/to/file
git checkout --theirs path/to/file
git add path/to/file
git rebase --continue
Prevention Strategies
- Pull/rebase frequently
- Keep branches short-lived
- Communicate about shared files
- Use code owners for critical paths
Git Configuration
Essential Configuration
git config --global user.name "Your Name"
git config --global user.email "your.email@example.com"
git config --global init.defaultBranch main
git config --global core.editor "code --wait"
git config --global diff.tool vscode
git config --global difftool.vscode.cmd 'code --wait --diff $LOCAL $REMOTE'
git config --global merge.tool vscode
git config --global mergetool.vscode.cmd 'code --wait $MERGED'
git config --global help.autocorrect 10
git config --global fetch.prune true
git config --global push.default current
git config --global push.autoSetupRemote true
Useful Aliases
[alias]
st = status -sb
lg = log --oneline --graph --decorate -20
lga = log --oneline --graph --decorate --all -20
co = checkout
cob = checkout -b
br = branch -vv
brd = branch -d
ci = commit
ca = commit --amend
can = commit --amend --no-edit
df = diff
dfs = diff --staged
unstage = reset HEAD --
uncommit = reset --soft HEAD~1
recent = for-each-ref --sort=-committerdate refs/heads/ --format='%(refname:short) - %(committerdate:relative)'
cleanup = "!git branch --merged | grep -v '\\*\\|main\\|master\\|develop' | xargs -n 1 git branch -d"
Common Operations
Undo Operations
git reset --soft HEAD~1
git reset HEAD~1
git reset --hard HEAD~1
git checkout -- path/to/file
git reset HEAD path/to/file
git revert <commit-sha>
Stashing
git stash
git stash save "WIP: feature description"
git stash -u
git stash list
git stash pop
git stash apply stash@{2}
git stash drop stash@{0}
Cherry-Picking
git cherry-pick <commit-sha>
git cherry-pick <sha1> <sha2> <sha3>
git cherry-pick <sha1>^..<sha2>
git cherry-pick -n <commit-sha>
Bisect (Find Bug Introduction)
git bisect start
git bisect bad
git bisect good <commit-sha>
git bisect good
git bisect reset
Safety Guidelines
Never Do on Shared Branches
git push --force origin main
git rebase main
git reset --hard HEAD~3
Safe Alternatives
git push --force-with-lease
git merge origin/main
git revert <sha>
Checklist
Before committing:
Before creating PR:
Anti-Patterns to Avoid
| Anti-Pattern | Problem | Solution |
|---|
git add . blindly | Commits unintended files | Use git add -p or specific files |
| "WIP" commits | Unclear history | Squash before merge |
| Force push to shared | Overwrites team work | Use --force-with-lease |
| Long-lived branches | Merge conflicts | Keep branches < 1 week |
| Large PRs | Slow reviews, bugs | Split into smaller PRs |
| Merge commits locally | Messy history | Rebase for updates |
| Ignoring CI failures | Broken main branch | Fix before merge |
Additional Resources