Skip to content

Instantly share code, notes, and snippets.

@spadgos
Last active March 22, 2021 21:28
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save spadgos/8097529 to your computer and use it in GitHub Desktop.
Save spadgos/8097529 to your computer and use it in GitHub Desktop.
Basic rebase and merge flow

Merging feature branches with rebase:

  1. git checkout master
  2. git pull --rebase to make sure you have the latest version of master
  3. git checkout feature/my-branch
  4. git rebase master ... to rebase this branch from master
    1. Optionally, git push --force to update the branch on github. This is useful for making sure it closes a pull request properly.
  5. git checkout master
  6. git merge --no-ff feature/my-branch ... merge the branch into master, making sure there's a merge commit

The effect:

Assuming there have been commits to master since the branch started, here is how the tree would look if just using git merge feature/my-branch

o   [master] Merge branch 'feature/my-branch' into master
|\
o | commit to master 3
o | commit to master 2
o | commit to master 1
| o [feature/my-branch] commit to branch 3
| o commit to branch 2
| o commit to branch 1
|/
o   commit to master

Or, worse, merge master into the branch then back into master:

o   [master] Merge branch 'feature/my-branch' into master
|\
| o [feature/my-branch] Merge branch master into 'feature/my-branch'
|/|
o | commit to master 3
o | commit to master 2
o | commit to master 1
| o commit to branch 3
| o commit to branch 2
| o commit to branch 1
|/
o   commit to master

And using rebase:

o   [master] Merge branch 'feature/my-branch' into master
|\
| o [feature/my-branch] commit to branch 3
| o commit to branch 2
| o commit to branch 1
|/
o   commit to master 3
o   commit to master 2
o   commit to master 1
o   commit to master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment