-
Notifications
You must be signed in to change notification settings - Fork 6
Git Workflow
gabriellesc edited this page Aug 26, 2017
·
1 revision
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:
- 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.
- Verify there are no local uncommitted changes.
- Run
git fetch
to acquire latest remote history - 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) - Kick off with
git rebase origin/<your-base-branch-typically-master>
- For every round of conflicts:
- 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 - Resolve conflicting blocks, picking the right lines of code, and removing all conflict markers by the end of it.
- Save the file!
- Double-check the file: there may be more than one conflicting block in a file. Confirm all conflict blocks are resolved.
- Mark the conflicting file as resolved with
git add <file-path>
- Tell git to continue with the rebase,
git rebase --continue
- Open conflicting file and find two sides of the conflict: they are delimited by
- Once the rebase is complete, verify the app is in functional state. That may include running tests, launching the app and browsing through it.
- If everything looks good at this point, use
git push -f origin <rebased-branch>
to override server’s history. - 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>
- 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.