Gangmax Blog

自由之思想,独立之精神

How to Merge Upstream Changes in Git

| Comments

This is a note about how to merge the diverged changes from an upstream branch(such as “master”) to your working branch(such as “f1”).

  1. Switch to the “master” branch and “git pull” to update to latest;

  2. Switch to the “f1” branch and “git pull” to update to latest;

  3. On the “f1” branch, run “git rebase master”;

  4. If there are conficts:

    1. “git status” to get the conflict file names list;

    2. Open each confilct file and fix the conflicts;

    3. Use “git add FILE” to mark each conflict file as resolved;

    4. Now run “git rebase –continue” to continue the “rebase” process;

    5. If conflicts happen, go back to step 1, until everything is merged;

  5. Now git tells you the following information, you need to run git pull again, and merge again:

1
2
3
4
5
6
On branch f1
Your branch and 'origin/f1' have diverged,
and have 114 and 11 different commits each, respectively.
  (use "git pull" to merge the remote branch into yours)

nothing to commit, working directory clean
  1. Run “git pull”, if you get conflicts:

    1. “git status” to get the conflict file names list;

    2. Open each confilct file and fix the conflicts;

    3. Run “git add FILES” and “git commit -m ‘comments’” to mark the conflict files as resolved;

    4. Run “git pull” to continue the pulling process;

    5. If conflicts happen, go back to step 1, until everything is merged;

  2. Run “git push origin f1” to push your merged/updated code from local to remote;

  3. Done.

Comments