Skip to content
goldy edited this page Feb 4, 2018 · 4 revisions

A brief description of git rebase could be "rebuild your branch as if it had just been created on top of the current master". Follow these instructions to rebase your branch to the head of master. For more information on rebasing, see Scott Chacon's description or the git rebase documentation.

First, if you are working on a branch in a fork, make sure you have the ESMCI remote in your repo:

git remote add ESMCI git@github.com:ESMCI/cime.git

1. Make sure your copy of ESMCI/master is up to date. Note that the 'master' branch may be from your fork or from ESMCI.

git checkout master
git pull --ff-only ESMCI

2. Check out your branch, you will rebase onto your branch.

git checkout <your_branch>

3. rebase. The first example is an automatic rebase:

git rebase master

The second method is interactive. It allows you the opportunity to combine commits and rewrite your commit messages.

git rebase --interactive master

You will be presented with an editor window showing all of your commits (since branching from master). If you want to combine commits, simply skip the first line and then change the pick at the beginning of each line to squash. Save and exit to allow the rebase to begin. When rebase is finished, it will again open an editor window to allow you to finalize your commit message (this may happen more than once).

Note that if, in the middle of a rebase (either version), the process runs into a conflict, edit the offending files to remove the conflicts (an easy way to see the files with conflicts is git diff --name-only --diff-filter=U), add in the edited files (git add <filename>) and continue the process (git rebase --continue).

When you are done, git log will show your modifications on top of the master branch.

4. Test your rebased repo. When you are satisfied, push it back to your fork or to ESMCI (here just called <remote>). Note that since you have changed your branch's history, you need to force the push since the branch you are pushing no longer agrees with the branch on github.

git push --force <remote> <your_branch>

Once you do this, make sure that anyone else using your branch starts over from the rebased branch on the server to avoid any future issues.

Clone this wiki locally