git-advancedlisted
Install: claude install-skill Sagargupta16/claude-skills
# Advanced Git Patterns
## Quick Reference
| Task | Command |
|------|---------|
| Rebase onto main | `git rebase main` |
| Interactive rebase (squash) | `git rebase -i HEAD~N` |
| Cherry-pick a commit | `git cherry-pick <sha>` |
| Find bug introduction | `git bisect start` |
| Stash with name | `git stash push -m "description"` |
| Undo last commit (keep changes) | `git reset --soft HEAD~1` |
| See what changed in a file | `git log -p -- path/to/file` |
| Find who changed a line | `git blame path/to/file` |
## Rebase Workflows
### Rebase feature branch onto main
```bash
git checkout feature-branch
git fetch origin
git rebase origin/main
# Fix conflicts if any, then:
git push --force-with-lease # safer than --force
```
Use `--force-with-lease` instead of `--force` -- it refuses to push if someone else has pushed to the branch since your last fetch.
### Interactive Rebase (clean up commits)
```bash
git rebase -i HEAD~5 # last 5 commits
```
In the editor:
```
pick abc1234 feat: add user model
squash def5678 fix typo in user model
squash ghi9012 more fixes
pick jkl3456 feat: add user routes
fixup mno7890 cleanup
```
| 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` | Remove commit entirely |
### When to Rebase vs Merge
| Rebase | Merge |
|--------|-------|
| Your feature branch behind main |