Git Merge & Rebase Commands[cheatsheet]

Luka
2 min readFeb 9, 2020

--

Git merge and git rebase, both are used to commit changes from one branch into another. The distinction is that both commands are accomplishing this service differently. “Rebasing re-writes the project history by creating brand new commits for each commit in the original branch.” Below are some useful commands for merging and rebasing.

Merge & Rebase

Merge branch into your current HEAD:

$ git merge <branch>

Rebase your current HEAD onto <branch>:

Don’t rebase published commit!

$ git rebase <branch>

Abort a rebase:

$ git rebase --abort

Continue a rebase after resolving conflicts:

$ git rebase --continue

Use your editor to manually solve conflicts and (after resolving) mark file as resolved:

$ git add <resolved-file>$ git rm <resolved-file>

Squashing commits:

$ git rebase -i <commit-just-before-first>

Now replace this,

pick <commit_id>
pick <commit_id2>
pick <commit_id3>

to this,

pick <commit_id>
squash <commit_id2>
squash <commit_id3>

Resources:

--

--

Luka

Software Engineer with a focus on building interactive and impactful applications. JS, React, Ruby on Rails.