| name | git-workflows |
| description | Advanced git operations beyond add/commit/push. Use when rebasing, bisecting bugs, using worktrees for parallel development, recovering with reflog, managing subtrees/submodules, resolving merge conflicts, cherry-picking across branches, or working with monorepos. |
| layer | base |
| skill_type | tool |
| dependencies | ["git-essentials"] |
Git Workflows
Advanced git operations for real-world development. Covers interactive rebase, bisect, worktree, reflog recovery, subtrees, submodules, sparse checkout, conflict resolution, and monorepo patterns.
When to Use
- Cleaning up commit history before merging (interactive rebase)
- Finding which commit introduced a bug (bisect)
- Working on multiple branches simultaneously (worktree)
- Recovering lost commits or undoing mistakes (reflog)
- Managing shared code across repos (subtree/submodule)
- Resolving complex merge conflicts
- Cherry-picking commits across branches or forks
- Working with large monorepos (sparse checkout)
Interactive Rebase
Squash, reorder, edit commits
git rebase -i HEAD~5
git rebase -i main
The editor opens with a pick list:
pick a1b2c3d Add user model
pick e4f5g6h Fix typo in user model
pick i7j8k9l Add user controller
pick m0n1o2p Add user routes
pick q3r4s5t Fix import in controller
Commands available:
pick = use commit as-is
reword = use commit but edit the message
edit = stop after this commit to amend it
squash = merge into previous commit (keep both messages)
fixup = merge into previous commit (discard this message)
drop = remove the commit entirely
Common patterns
pick a1b2c3d Add user model
fixup e4f5g6h Fix typo in user model
pick i7j8k9l Add user controller
fixup q3r4s5t Fix import in controller
pick m0n1o2p Add user routes
pick i7j8k9l Add user controller
pick m0n1o2p Add user routes
pick a1b2c3d Add user model
git reset HEAD~
git add src/model.ts
git commit -m "Add user model"
git add src/controller.ts
git commit -m "Add user controller"
git rebase --continue
Autosquash (commit messages that auto-arrange)
git commit --fixup=a1b2c3d -m "Fix typo"
git commit --squash=a1b2c3d -m "Additional changes"
git rebase -i --autosquash main
Abort or continue
git rebase --abort
git rebase --continue
git rebase --skip
Bisect (Find the Bug)
Binary search through commits
git bisect start
git bisect bad
git bisect good v1.2.0
git bisect good
git bisect bad
git bisect reset
Automated bisect (with a test script)
git bisect start HEAD v1.2.0
git bisect run ./test-for-bug.sh
cat > /tmp/test-for-bug.sh << 'EOF'
npm test -- --grep "login should redirect" 2>/dev/null
EOF
chmod +x /tmp/test-for-bug.sh
git bisect run /tmp/test-for-bug.sh
Bisect with build failures
git bisect skip
git bisect skip v1.3.0..v1.3.5
Worktree (Parallel Branches)
Work on multiple branches simultaneously
git worktree add ../myproject-hotfix hotfix/urgent-fix
git worktree add ../myproject-feature -b feature/new-thing
git worktree list
git worktree remove ../myproject-hotfix
git worktree prune
Use cases
git worktree add ../review-pr-123 origin/pr-123
git worktree add ../main-tests main
cd ../main-tests && npm test
git worktree add ../compare-old release/v1.0
git worktree add ../compare-new release/v2.0
Reflog (Recovery)
See everything git remembers
git reflog
git reflog show feature/my-branch
git reflog --date=relative
Recover from mistakes
git reflog
git reset --hard ghi789
git reflog
git branch recovered-branch abc123
git reflog
git reset --hard HEAD@{2}
git fsck --unreachable | grep commit
git stash list
git log --walk-reflogs --all -- stash
Cherry-Pick
Copy specific commits to another branch
git cherry-pick abc123
git cherry-pick abc123 def456 ghi789
git cherry-pick abc123..ghi789
git cherry-pick --no-commit abc123
git remote add upstream https://github.com/other/repo.git
git fetch upstream
git cherry-pick upstream/main~3
Handle conflicts during cherry-pick
git add resolved-file.ts
git cherry-pick --continue
git cherry-pick --abort
Subtree and Submodule
Subtree (simpler — copies code into your repo)
git subtree add --prefix=lib/shared https://github.com/org/shared-lib.git main --squash
git subtree pull --prefix=lib/shared https://github.com/org/shared-lib.git main --squash
git subtree push --prefix=lib/shared https://github.com/org/shared-lib.git main
git subtree split --prefix=lib/shared -b shared-lib-standalone
Submodule (pointer to another repo at a specific commit)
git submodule add https://github.com/org/shared-lib.git lib/shared
git clone --recurse-submodules https://github.com/org/main-repo.git
git submodule update --init --recursive
git submodule update --remote
git rm lib/shared
rm -rf .git/modules/lib/shared
When to use which
Subtree: Simpler, no special commands for cloners, code lives in your repo.
Use when: shared library, vendor code, infrequent upstream changes.
Submodule: Pointer to exact commit, smaller repo, clear separation.
Use when: large dependency, independent release cycle, many contributors.
Sparse Checkout (Monorepo)
Check out only the directories you need
git sparse-checkout init --cone
git sparse-checkout set packages/my-app packages/shared-lib
git sparse-checkout add packages/another-lib
git sparse-checkout list
git sparse-checkout disable
Clone with sparse checkout (large monorepos)
git clone --filter=blob:none --sparse https://github.com/org/monorepo.git
cd monorepo
git sparse-checkout set packages/my-service
git clone --no-checkout https://github.com/org/monorepo.git
cd monorepo
git sparse-checkout set packages/my-service
git checkout main
Conflict Resolution
Understand the conflict markers
<<<<<<< HEAD (or "ours")
Your changes on the current branch
=======
Their changes from the incoming branch
>>>>>>> feature-branch (or "theirs")
Resolution strategies
git checkout --ours path/to/file.ts
git add path/to/file.ts
git checkout --theirs path/to/file.ts
git add path/to/file.ts
git checkout --ours .
git add .
git mergetool
git diff --cc path/to/file.ts
git show :1:path/to/file.ts
git show :2:path/to/file.ts
git show :3:path/to/file.ts
Rebase conflict workflow
git add fixed-file.ts
git rebase --continue
git rebase --skip
Rerere (reuse recorded resolutions)
git config --global rerere.enabled true
ls .git/rr-cache/
git rerere forget path/to/file.ts
Stash Patterns
git stash push -m "WIP: refactoring auth flow"
git stash push -m "partial stash" -- src/auth.ts src/login.ts
git stash push -u -m "with untracked"
git stash list
git stash apply
git stash pop
git stash apply stash@{2}
git stash show -p stash@{0}
git stash branch new-feature stash@{0}
git stash drop stash@{1}
git stash clear
Blame and Log Archaeology
git blame src/auth.ts
git blame -L 50,70 src/auth.ts
git blame -w src/auth.ts
git log -S "function oldName" --oneline
git log -G "TODO.*hack" --oneline
git log --follow --oneline -- src/new-name.ts
git blame -M src/auth.ts
git log --stat --oneline -20
git log --oneline -- src/auth.ts
git show abc123
Tags and Releases
git tag -a v1.2.0 -m "Release 1.2.0: Added auth module"
git tag v1.2.0
git tag -a v1.1.0 abc123 -m "Retroactive tag for release 1.1.0"
git tag -l
git tag -l "v1.*"
git push origin v1.2.0
git push origin --tags
git tag -d v1.2.0
git push origin --delete v1.2.0
Tips
git rebase -i is the single most useful advanced git command. Learn it first.
- Never rebase commits that have been pushed to a shared branch. Rebase your local/feature work only.
git reflog is your safety net. If you lose commits, they're almost always recoverable within 90 days.
git bisect run with an automated test is faster than manual binary search and eliminates human error.
- Worktrees are cheaper than multiple clones — they share
.git storage.
- Prefer
git subtree over git submodule unless you have a specific reason. Subtrees are simpler for collaborators.
- Enable
rerere globally. It remembers conflict resolutions so you never solve the same conflict twice.
git stash push -m "description" is much better than bare git stash. You'll thank yourself when you have 5 stashes.
git log -S "string" (pickaxe) is the fastest way to find when a function or variable was added or removed.
Reference
Advanced git workflows skill for NeuroClaw. Complements git-essentials for basic operations.
Complementary / Related Skills
claw-shell → all Git commands are safely executed through claw-shell
Created At: 2026-03-19
Last Updated At: 2026-03-26 00:01 HKT
Author: chengwang96