Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lucas1richard/3a2051eb5000ee2d43a9286f04f6e102 to your computer and use it in GitHub Desktop.
Save lucas1richard/3a2051eb5000ee2d43a9286f04f6e102 to your computer and use it in GitHub Desktop.
Git rebase workflow
# first, fetch the latest refs for all branches. And be sure we have latest master, etc
git checkout master
git fetch
# If any changes from remote, catch our local version up
git rebase origin/master
# could also be done as
# git pull -r origin master
#########
# 1
# Start a new branch to work on a feature
git checkout -b foo
#########
# 2
# Commit locally ... some time passes
#########
# 3
# Ready to push 'foo' to remote, but another team member working on our branch already pushed changes to remote
git fetch
# Let's rebase our local branch on top of the latest from remote
# still on branch "foo" ...
# git branch => 'foo'
git rebase origin/foo
# resolve conflicts then push to remote
#########
# 4
# There was a release to production so there are changes in master
# Let's take our new commits, and place it on top of the latest master
git rebase origin/master
# could also be done as
# git checkout master
# assuming you have nothing in your local master
# git pull origin master
#########
# 6
# now you're local master is fresh, so we can replay our branch's commits on top
git checkout foo
git rebase master
# now foo has the latest master plus the new commits
git push origin foo
#########
# 7
# Time to release our code!
# We want our code in master, so let's rebase on top of master and then we'll Fast-Forward merge our branch into master
# update master
git branch
git checkout master
git fetch
git rebase origin/master
# update our branch
git checkout foo
git rebase origin/foo
#########
# From branch foo, we take our new commits and replay them on top of the latest master
# still on branch "foo"
# git branch => "foo"
git rebase origin/master
#########
# resolve any conflicts that git cannot resolve itself
# repeat this until there are no conflicts
git mergetool
# ... open your mergetool
# ... save the merged version using your mergetool
git rebase --continue
##########
# 8
# Merge back into master
git checkout master
git merge foo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment