Agent skill
git-workflows
Advanced git operations - branching strategies, interactive rebase, conflict resolution, stash management, and disaster recovery. Auto-triggers for complex git tasks.
Install this agent skill to your Project
npx add-skill https://github.com/majiayu000/claude-skill-registry/tree/main/skills/other/other/git-workflows-bigdegenenergy-open-cloud-ops
SKILL.md
Git Workflows Skill
Branching Strategies
GitHub Flow (Recommended for Most Projects)
main ──────●────────●────────●──────
\ / \ /
feature-1 ●──●── ●──●
feature-2
- Branch from
main - Make changes, commit
- Open PR, get review
- Merge to
main, delete branch
Branch Naming
# Pattern: type/description
feature/oauth-login
fix/null-pointer-user-profile
refactor/extract-auth-module
docs/api-endpoints
chore/upgrade-dependencies
Interactive Rebase
Clean Up Before PR
# Rebase last 4 commits
git rebase -i HEAD~4
# In editor:
pick abc1234 feat: add user model
squash def5678 fix typo in user model # Combine with previous
pick ghi9012 feat: add user API endpoint
fixup jkl3456 cleanup # Combine, discard message
| Command | Effect |
|---|---|
pick |
Keep commit as-is |
squash |
Merge into previous, combine messages |
fixup |
Merge into previous, discard message |
reword |
Keep commit, edit message |
drop |
Delete commit entirely |
edit |
Pause to amend commit |
Rebase onto Updated Main
# Update main
git fetch origin main
# Rebase feature branch onto latest main
git rebase origin/main
# If conflicts: resolve, then continue
git add .
git rebase --continue
# Abort if things go wrong
git rebase --abort
Conflict Resolution
Step-by-Step
# 1. See what conflicts exist
git status
# 2. Open conflicted file - markers look like:
<<<<<<< HEAD
current_change()
=======
incoming_change()
>>>>>>> feature-branch
# 3. Resolve by keeping correct code (remove markers)
resolved_change()
# 4. Mark as resolved
git add <resolved-file>
# 5. Continue the operation
git rebase --continue # or git merge --continue
Conflict Prevention
- Rebase feature branches onto main frequently
- Keep PRs small and focused
- Communicate about shared files
- Use
.gitattributesfor merge strategies on generated files
# .gitattributes - always use ours for lock files
uv.lock merge=ours
package-lock.json merge=ours
Stash Management
# Stash current changes with description
git stash push -m "WIP: auth refactor"
# List stashes
git stash list
# Apply most recent stash (keep in stash list)
git stash apply
# Apply and remove from stash list
git stash pop
# Apply specific stash
git stash apply stash@{2}
# Stash specific files
git stash push -m "partial work" src/auth.py src/middleware.py
# Stash including untracked files
git stash push -u -m "including new files"
# Drop a stash
git stash drop stash@{0}
# Clear all stashes
git stash clear
Cherry-Pick
# Apply a specific commit to current branch
git cherry-pick abc1234
# Cherry-pick without committing (stage only)
git cherry-pick --no-commit abc1234
# Cherry-pick a range
git cherry-pick abc1234..def5678
# If conflicts during cherry-pick
git cherry-pick --continue # after resolving
git cherry-pick --abort # to cancel
Disaster Recovery
Undo Last Commit (Keep Changes)
git reset --soft HEAD~1
Recover Deleted Branch
# Find the commit hash from reflog
git reflog | grep "branch-name"
# Recreate the branch
git branch recovered-branch abc1234
Recover Lost Commits
# View full history including orphaned commits
git reflog
# Find the commit you need and checkout/cherry-pick
git cherry-pick abc1234
Undo a Bad Merge
# Revert a merge commit (keeps history clean)
git revert -m 1 <merge-commit-hash>
Find When a Bug Was Introduced
# Start bisect
git bisect start
# Mark current as bad
git bisect bad
# Mark a known good commit
git bisect good v1.0.0
# Git checks out a middle commit - test it, then:
git bisect good # or git bisect bad
# Repeat until git finds the culprit
# When done:
git bisect reset
Automated Bisect
# Run a test script at each step
git bisect start HEAD v1.0.0
git bisect run pytest tests/test_auth.py
Worktrees (Parallel Branches)
# Work on two branches simultaneously
git worktree add ../my-project-hotfix hotfix/urgent-fix
# List worktrees
git worktree list
# Remove when done
git worktree remove ../my-project-hotfix
Useful Aliases
# Add to ~/.gitconfig
[alias]
lg = log --oneline --graph --all --decorate
st = status -sb
unstage = reset HEAD --
last = log -1 HEAD --stat
branches = branch -a --sort=-committerdate
amend = commit --amend --no-edit
Activation Triggers
This skill auto-activates when prompts contain:
- "rebase", "cherry-pick", "stash"
- "merge conflict", "resolve conflict"
- "git bisect", "git reflog", "recover"
- "branch strategy", "branching"
- "worktree", "git reset"
Integration
- conventional-commits skill: Commit message formatting
- /merge-resolve command: Conflict resolution
- /ship command: Push and PR workflow
Recommended Agent Skills
Expand your agent's capabilities with these related and highly-rated skills.
agent-ops-spec
Manage specification documents in .agent/specs/. Use when user provides requirements, acceptance criteria, or feature descriptions that need to be tracked and validated against implementation.
agent-ops-state
Maintain .agent state files. Use at session start, after meaningful steps, and before concluding: read/update constitution/memory/focus/issues/baseline consistently.
agent-ops-spec
Manage specification documents in .agent/specs/. Use when user provides requirements, acceptance criteria, or feature descriptions that need to be tracked and validated against implementation.
agent-ops-testing
Test strategy, execution, and coverage analysis. Use when designing tests, running test suites, or analyzing test results beyond baseline checks.
agent-ops-testing
Test strategy, execution, and coverage analysis. Use when designing tests, running test suites, or analyzing test results beyond baseline checks.
agent-ops-state
Maintain .agent state files. Use at session start, after meaningful steps, and before concluding: read/update constitution/memory/focus/issues/baseline consistently.
Didn't find tool you were looking for?