MyAIDevelopment · Product · Operations notes

Merge, Rebase, Cherry-pick

All three can be confusing because they “bring in other changes.”

The most important first step is to identify the acting branch and the target.

In most commands, the currently checked-out branch is the acting branch.

Merge

When the current branch is feature:

git merge stable
gitGraph
   commit id:"A"
   commit id:"B"
   branch feature
   checkout feature
   commit id:"E"
   commit id:"F"
   checkout main
   commit id:"C"
   commit id:"D"
   checkout feature
   merge main id:"M"

Existing commits are preserved, and branching and merging remain visible in history.

Rebase

While currently on feature:

git rebase origin/stable
Before

A ─ B ─ C ─ D   stable
           E ─ F     feature

After rebase

A ─ B ─ C ─ D   stable
                             E' ─ F' feature

An Important Misconception

Rebasing does not delete the feature branch or merge it into stable.

stable  → D
feature → F'

Both branches remain.

The later PR + Merge step is what actually brings the changes into stable.

Why Pushing Can Become a Problem

Rebase changes commit hashes.

If you rebase a feature branch that has already been pushed to the remote, a normal push may be rejected. Consider --force-with-lease only when team policy permits it.

Cherry-pick

From the current branch:

git cherry-pick abc123
feature-A
A ─ B ─ C

feature-B
X ─ Y ─ C'

C has not moved; its patch has been reapplied as C'.

Choosing an Operation

Situation Choice
Combine two branch histories as they are Merge
Place your feature on top of the latest stable Rebase
Need only one commit from another branch Cherry-pick

Handling Conflicts

Merge

git merge --abort

Rebase

git add <resolved>
git rebase --continue
git rebase --abort

Cherry-pick

git add <resolved>
git cherry-pick --continue
git cherry-pick --abort

Operating Principles for Beginners