Skip to content

Git Workflow

gabriellesc edited this page Aug 26, 2017 · 1 revision

Rebasing

This guide describes how to rebase a branch. Rebasing is a process by which you change the the starting point, base, of your branch. Most commonly, you want to rebase your branch because the branch you have started your work on received updates.

Here's what rebasing does, visually:

  1. Notify anyone who may be working on the same branch that you are rebasing! They should commit and push all of their changes before you begin.
  2. Verify there are no local uncommitted changes.
  3. Run git fetch to acquire latest remote history
  4. Verify with git status that local branch you’re rebasing is in sync with remote (ie., there are no unpushed commits and branches are not diverged)
  5. Kick off with git rebase origin/<your-base-branch-typically-master>
  6. For every round of conflicts:
    1. Open conflicting file and find two sides of the conflict: they are delimited by <<<… for start of the first version, ===… to separate the two versions, >>> at the end of conflicting blocks
    2. Resolve conflicting blocks, picking the right lines of code, and removing all conflict markers by the end of it.
    3. Save the file!
    4. Double-check the file: there may be more than one conflicting block in a file. Confirm all conflict blocks are resolved.
    5. Mark the conflicting file as resolved with git add <file-path>
    6. Tell git to continue with the rebase, git rebase --continue
  7. Once the rebase is complete, verify the app is in functional state. That may include running tests, launching the app and browsing through it.
  8. If everything looks good at this point, use git push -f origin <rebased-branch> to override server’s history.
  9. Notify anyone else working on the same branch that you’ve completed the rebase. They will need to get their local copies in sync with the update using git fetch; git checkout <rebased-branch>; git reset --hard origin/<rebased-branch>
  10. Rebase is complete!

Two important notes:

  • In case of confusion (ie., not sure what’s going on, you seem to be going in circles, something doesn’t feel right), use git rebase --abort to back out of the rebase.
  • After a rebase, git will tell you your branches have diverged: Your branch and 'origin/<your-branch>' have diverged. That’s correct. If you ran the rebase, see step 7; if someone else ran the rebase, see step 8.