100% Free Forever
AI-Powered Learning
Industry Expert Content
Certificates & Badges
Learn At Your Own Pace

Git Advanced (Rebase/Cherry-pick) Cheat Sheet

Git Advanced (Rebase/Cherry-pick) Cheat Sheet

Advanced Git history manipulation techniques including interactive rebase, cherry-picking, and conflict resolution.

2 PagesAdvancedFeb 18, 2026

Rebasing onto Main

Replay your branch's commits on top of the latest main.

bash
git fetch origingit checkout feature-branchgit rebase origin/main# If conflicts occur, resolve files then:git add <resolved-file>git rebase --continue# Abort and return to pre-rebase stategit rebase --abort

Interactive Rebase

Rewrite the last 4 commits: squash, reword, or drop them.

bash
git rebase -i HEAD~4# In the editor, change 'pick' to:#   reword - edit the commit message#   squash - combine into previous commit, keep both messages#   fixup  - combine into previous commit, discard this message#   drop   - remove the commit entirely#   edit   - pause to amend the commit

Cherry-picking Commits

Apply a specific commit from another branch onto the current one.

bash
git cherry-pick abc1234# Cherry-pick a range of commits (exclusive of first)git cherry-pick abc1234..def5678# Cherry-pick without auto-committing, to inspect firstgit cherry-pick -n abc1234# Continue after resolving a cherry-pick conflictgit cherry-pick --continue

Recovering with reflog

Find and restore commits that seem lost after a bad rebase or reset.

bash
git reflog# e.g. abc1234 HEAD@{2}: rebase (start): checkout maingit reset --hard HEAD@{2}   # restore to a previous state# orgit cherry-pick abc1234      # reapply a specific lost commit

Rebase vs Merge

When to choose one strategy over the other.

  • Rebase- Produces a linear history by replaying commits; rewrites SHAs, avoid on shared/public branches
  • Merge- Preserves true history with a merge commit; safe on shared branches
  • golden rule- Never rebase commits that have already been pushed and pulled by others
Pro Tip

Before an interactive rebase you're unsure about, create a safety branch (`git branch backup-before-rebase`) — if it goes wrong, `git reflog` can recover it, but a named branch pointer is faster and less error-prone.

Was this cheat sheet helpful?

Explore Topics

#GitAdvancedRebaseCherryPick#GitAdvancedRebaseCherryPickCheatSheet#DevOps#Advanced#RebasingOntoMain#InteractiveRebase#CherryPickingCommits#RecoveringWithReflog#Git#CheatSheet#SkillVeris
Advertisement
Sri Hayavadhana Info-Tech

Professional Web Designing Services

  • Responsive Websites
  • E-commerce Solutions
  • SEO Friendly Design
  • Fast & Secure
  • Support & Maintenance
Get a Free Quote

Share this Cheat Sheet