| name | git-collaboration |
| description | Collaboration workflows for team-based Git development. Covers pull request workflows, merge vs rebase strategies, conflict resolution, code review practices, and branch protection. Helps AI agents follow team conventions and collaborate effectively. |
Git Collaboration Workflows
Purpose: This skill teaches AI agents to collaborate effectively in team environments using Git, including PR workflows, merge strategies, and conflict resolution.
Core Principles
- Sync Early, Sync Often - Stay up to date with main branch
- Small, Focused PRs - Easier to review and merge
- Clean History - Use rebase for clean, linear history
- Review-Friendly - Structure changes for easy review
Branch Workflow Strategies
Strategy 1: Feature Branch Workflow (Recommended)
git switch main
git pull
git switch -c feature/add-user-authentication
git add src/auth.js
git commit -m "feat(auth): add login endpoint"
git fetch origin
git rebase origin/main
git push -u origin feature/add-user-authentication
gh pr create --title "Add user authentication" --body "..."
git switch main
git pull
git branch -d feature/add-user-authentication
When to use:
- Standard for most teams
- Clear separation of features
- Easy to review individual features
Strategy 2: Trunk-Based Development
git switch main
git pull
git switch -c fix/cart-validation
git add src/cart.js
git commit -m "fix(cart): validate quantity range"
git push -u origin fix/cart-validation
gh pr create --title "Fix cart validation"
git switch main
git pull
git branch -d fix/cart-validation
When to use:
- Fast-moving teams
- Continuous integration culture
- Small, incremental changes
Strategy 3: Release Branch Workflow
git switch main
git switch -c release/v2.0
git switch -c hotfix/fix-critical-bug
git add src/payment.js
git commit -m "fix(payment): prevent double charging"
git switch release/v2.0
git merge hotfix/fix-critical-bug
git switch main
git merge hotfix/fix-critical-bug
git switch release/v2.0
git tag -a v2.0.1 -m "Release v2.0.1"
git push origin v2.0.1
When to use:
- Supporting multiple versions
- Long release cycles
- Need stable release branches
Pull Request Workflow
Creating a Pull Request
git switch feature/new-feature
git fetch origin
git rebase origin/main
git log origin/main..HEAD
git diff origin/main...HEAD
git push -u origin feature/new-feature
gh pr create \
--title "feat(auth): add OAuth2 authentication" \
--body "$(cat <<'EOF'
## Summary
Adds OAuth2 authentication support for Google and GitHub providers.
## Changes
- Add OAuth2 client configuration
- Implement callback handler
- Add user profile mapping
- Update login UI with OAuth buttons
## Testing
- ✅ Manual testing with Google OAuth
- ✅ Manual testing with GitHub OAuth
- ✅ Added unit tests for profile mapping
- ✅ Verified error handling for invalid tokens
## Screenshots
[Attach screenshots of login page]
## Checklist
- [x] Tests added/updated
- [x] Documentation updated
- [x] No breaking changes
- [ ] Security review needed (OAuth credentials handling)
Closes #234
EOF
)"
PR Description Template
## Summary
Brief description of what this PR does and why.
## Changes
- Bullet point list of main changes
- Keep it high-level (detailed changes visible in commits)
## Testing
- [ ] Unit tests added/updated
- [ ] Integration tests added/updated
- [ ] Manual testing performed
- [ ] Edge cases verified
## Deployment Notes
Any special deployment steps, migrations, or config changes needed.
## Checklist
- [ ] Tests passing
- [ ] Documentation updated
- [ ] No breaking changes (or clearly documented)
- [ ] Reviewed own code
- [ ] Ready for review
Closes #<issue-number>
Responding to Review Feedback
git add src/auth.js
git commit -m "refactor(auth): extract validation to separate function"
git add tests/auth.test.js
git commit -m "test(auth): add edge cases for token validation"
git push
git commit --amend
git push --force
Why new commits during review:
- Reviewers can see what changed since last review
- Clear history of feedback iterations
- Can be squashed later before merge
Squashing Before Merge
git switch feature/new-feature
git rebase -i origin/main
pick abc123 feat(auth): add OAuth2 support
squash def456 refactor(auth): extract validation
squash ghi789 test(auth): add edge cases
squash jkl012 fix(auth): address review comments
git push --force-with-lease origin feature/new-feature
gh pr merge --squash
Merge vs Rebase vs Squash
Decision Tree
Are you working on a feature branch?
├─ Ready to integrate to main?
│ ├─ Want to preserve all commit history?
│ │ └─> Merge commit (git merge --no-ff)
│ │
│ └─ Want clean, single commit?
│ └─> Squash merge (git merge --squash)
│
└─ Want to stay up to date with main?
└─> Rebase (git rebase origin/main)
Strategy Comparison
| Strategy | Command | Result | Use When |
|---|
| Merge | git merge feature | Creates merge commit, preserves all commits | Want to preserve feature branch history |
| Rebase | git rebase main | Replays commits on top of main | Updating feature branch, want linear history |
| Squash | git merge --squash feature | Combines all commits into one | Want clean history, PRs with many small commits |
Merge Commit
git switch main
git merge --no-ff feature/new-feature
Rebase
git switch feature/new-feature
git fetch origin
git rebase origin/main
git push --force-with-lease origin feature/new-feature
Squash Merge
gh pr merge --squash
git switch main
git merge --squash feature/new-feature
git commit -m "feat(auth): add OAuth2 authentication
Summary of all changes from feature branch.
Includes implementation, tests, and documentation.
Closes #234"
Conflict Resolution
Preventing Conflicts
git switch feature/new-feature
git fetch origin
git rebase origin/main
Resolving Merge Conflicts
git rebase origin/main
git status
git add src/auth.js
git rebase --continue
git push --force-with-lease origin feature/new-feature
Conflict Resolution Strategies
git checkout --ours src/auth.js
git checkout --theirs src/auth.js
git add src/auth.js
git rebase --continue
git mergetool
git rebase --abort
git merge --abort
Complex Conflict Example
function authenticate(username, password) {
// New validation added in main
if (!username || !password) {
throw new Error('Missing credentials');
}
return validateCredentials(username, password);
}
function authenticate(credentials) {
// Your change: accept object instead
return validateCredentials(credentials.username, credentials.password);
}
function authenticate(credentials) {
// Keep new validation from main
if (!credentials.username || !credentials.password) {
throw new Error('Missing credentials');
}
// Keep your signature change
return validateCredentials(credentials.username, credentials.password);
}
git add src/auth.js
git rebase --continue
Code Review Best Practices
For PR Authors
git diff origin/main...HEAD
npm test
npm run lint
git diff origin/main...HEAD | grep -i console.log
git diff origin/main...HEAD | grep -i debugger
git log origin/main..HEAD --oneline
git rebase -i origin/main
PR Size Guidelines
git switch -c feature/part-1
git cherry-pick <commits for part 1>
git push -u origin feature/part-1
git switch -c feature/part-2
git cherry-pick <commits for part 2>
git push -u origin feature/part-2
For Reviewers
Review checklist:
Branch Protection Rules
Recommended Settings
Protected Branch Rules for 'main':
Require pull request reviews:
✓ Enabled
Required approvals: 1-2
Dismiss stale reviews: ✓
Require review from code owners: ✓
Require status checks:
✓ Enabled
Required checks:
- CI tests
- Linting
- Security scan
Require branches to be up to date: ✓
Require linear history: ✓ (no merge commits)
Restrictions:
✓ Include administrators
Allow force pushes: ✗
Allow deletions: ✗
Working with Protected Branches
git switch main
git commit -m "feat: quick fix"
git push origin main
git switch -c fix/quick-fix
git commit -m "feat: quick fix"
git push -u origin fix/quick-fix
gh pr create
Common Workflows
Workflow 1: Standard Feature Development
git switch main
git pull
git switch -c feature/user-notifications
git add src/notifications.js
git commit -m "feat(notifications): add email notification service"
git add tests/notifications.test.js
git commit -m "test(notifications): add email service tests"
git push -u origin feature/user-notifications
git fetch origin
git rebase origin/main
git push --force-with-lease origin feature/user-notifications
git add src/notifications.js
git commit -m "feat(notifications): add SMS notification support"
git push
gh pr create --title "Add user notification system"
git add src/notifications.js
git commit -m "refactor(notifications): extract provider interface"
git push
gh pr merge --squash
git switch main
git pull
git branch -d feature/user-notifications
Workflow 2: Hotfix
git switch main
git pull
git switch -c hotfix/fix-payment-crash
git add src/payment.js
git commit -m "fix(payment): prevent crash on null amount"
git push -u origin hotfix/fix-payment-crash
gh pr create \
--title "HOTFIX: Fix payment crash on null amount" \
--label "hotfix" \
--body "Critical bug causing payment crashes in production"
gh pr merge --squash
git switch main
git pull
git branch -d hotfix/fix-payment-crash
Workflow 3: Collaborative Feature
git switch -c feature/new-dashboard
git push -u origin feature/new-dashboard
git fetch origin
git switch -c feature/new-dashboard-widgets origin/feature/new-dashboard
git add src/widgets.js
git commit -m "feat(dashboard): add widget system"
git push -u origin feature/new-dashboard-widgets
gh pr create --base feature/new-dashboard
git switch feature/new-dashboard
git pull
git switch feature/new-dashboard
gh pr create --base main
Summary
Key Principles:
- Feature branch workflow - Standard for most teams
- Small, focused PRs - Easier to review and merge
- Rebase to stay current - Linear history, cleaner log
- Squash before merge - Clean main branch history
- Resolve conflicts early - Rebase frequently
Essential Commands:
git switch -c feature/name
git rebase origin/main
git push --force-with-lease
gh pr create
gh pr merge --squash
git branch -d feature/name
Remember: Good collaboration is about clear communication, clean history, and making reviewers' lives easier.