Skip to content

Instantly share code, notes, and snippets.

@meagar
Created April 30, 2014 16:01
Show Gist options
  • Star 11 You must be signed in to star a gist
  • Fork 6 You must be signed in to fork a gist
  • Save meagar/ae2c7f1b200d7fa52508 to your computer and use it in GitHub Desktop.
Save meagar/ae2c7f1b200d7fa52508 to your computer and use it in GitHub Desktop.
Ultimate rebase-onto-master guide

Rebase "web-123-my-branch" onto master:

if you're the only person who is working on a branch...

$ git checkout web-123-my-branch # make sure you're on the right branch
$ git fetch # update remote refs
$ git rebase origin/master # perform the rebase onto the current state of master
  # for each conflict, edit file, resolve conflicts, git add -u <file>, git rebase --continue
$ git push -f origin web-123-my-branch # overwrite remote branch with newly rebase branch

if you're not the only person working on a branch...

Don't rebase! Or, one person who is working on the branch, follow above steps, then, all other people...

$ git checkout web-123-my-branch # make sure you're on the right branch
$ git fetch # update remote refs
$ git reset --hard origin/web-123-my-branch # discard the state of your branch, move to the newly rebased branch

"Rebase" web-123-my-branch onto master, squashing all commits

$ git checkout web-123-my-branch
$ git fetch
$ git reset --hard origin/master # move your branch to the current state of master
$ git merge --squash head@{1} # merge all changes from your branch into the index
$ git status # verify changes to be committed
$ git commit # edit all commit messages from previous commits down to a single sane commit message
$ git push -f origin web-123-my-branch # overwrite remote branch with newly rebase branch

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment