跳至內容

Git Workflows Cheatsheet

Published: at 12:00 AM

Git Workflows Cheatsheet

Fast reminders for daily Git housekeeping: creating isolated worktrees, tidying history with squashed commits, and moving patches with cherry-pick.

Worktrees

# Typical flow
git fetch origin
git worktree add ../bugfix-login origin/bugfix/login
cd ../bugfix-login
# ... work, commit, push ...
cd -
git worktree remove ../bugfix-login

Tips

Squashing Commits

Interactive rebase (preferred)

git fetch origin
git rebase -i origin/main
# mark commits as `squash` or `fixup`
git push --force-with-lease

Merge squash for feature branch handoff

git checkout main
git pull origin main
git merge --squash feature/login-audit
git commit -m "feat: add login audit trail"

Cherry-picking Commits

git checkout release/2025.02
git cherry-pick f2c1d7e
# resolve conflicts if any, then
git cherry-pick --continue

Conflict handling