| name | git-advanced-1-interactive-rebase |
| description | Sub-skill of git-advanced: 1. Interactive Rebase (+1). |
| version | 1.0.0 |
| category | operations |
| type | reference |
| scripts_exempt | true |
1. Interactive Rebase (+1)
1. Interactive Rebase
Basic Interactive Rebase:
git rebase -i HEAD~5
git rebase -i main
git rebase -i abc123^
Interactive Rebase Commands:
pick abc123 First commit # Use commit as-is
reword def456 Second commit # Edit commit message
edit ghi789 Third commit # Stop to amend
squash jkl012 Fourth commit # Combine with previous
fixup mno345 Fifth commit # Combine, discard message
drop pqr678 Sixth commit # Remove commit
Common Rebase Workflows:
git rebase -i main
git rebase -i HEAD~3
git rebase -i HEAD~3
git reset HEAD^
git add -p
git commit -m "First part"
git add .
git commit -m "Second part"
git rebase --continue
git rebase -i HEAD~3
Autosquash Pattern:
git commit --fixup=abc123
git commit --squash=abc123
git rebase -i --autosquash main
git config --global rebase.autosquash true
2. Git Worktrees
Basic Worktree Usage:
git worktree list
git worktree add ../feature-branch feature/new-feature
git worktree add -b hotfix/urgent ../hotfix-urgent main
git worktree remove ../feature-branch
git worktree prune
Worktree Workflow:
workspace/
├── main/
├── feature-auth/
├── hotfix-critical/# Hotfix branch
└── experiment/
cd main
git worktree add ../feature-auth feature/authentication
git worktree add ../hotfix-critical -b hotfix/critical-bug
git worktree add ../experiment -b experiment/new-approach
cd ../feature-auth
git commit -am "Add authentication"
cd ../hotfix-critical
git commit -am "Fix critical bug"
git push
cd ../feature-auth
Worktree Helper Script:
#!/bin/bash
set -e
WORKTREE_BASE="${WORKTREE_BASE:-$(dirname $(git rev-parse --git-dir))}"
case "$1" in
add)
BRANCH="$2"
DIR="${3:-$WORKTREE_BASE/../$(echo $BRANCH | tr '/' '-')}"
if git show-ref --verify --quiet "refs/heads/$BRANCH"; then
git worktree add "$DIR" "$BRANCH"
else
git worktree add -b "$BRANCH" "$DIR"
fi
echo "Created worktree at: $DIR"
;;
remove)
git worktree remove "$2"
;;
list)
git worktree list
;;
*)
echo "Usage: $0 {add|remove|list} [branch] [directory]"
exit 1
;;
esac