From: Oleg Broytman Date: Tue, 2 Jun 2015 16:58:55 +0000 (+0300) Subject: Add subsection "Updating local and remote branches" X-Git-Url: https://git.phdru.name/?a=commitdiff_plain;h=55fa2fd75bc22a08e48c8e4a8c0b4a3a74a90e06;p=git-wiki.git Add subsection "Updating local and remote branches" --- diff --git a/pep-git.txt b/pep-git.txt index 9f7eeea..31dc438 100644 --- a/pep-git.txt +++ b/pep-git.txt @@ -159,6 +159,54 @@ git clones remote repository ``http://git.python.org/python.git`` to directory ``python``, creates remote branches and checks out branch ``v1`` into the working directory. +Updating local and remote branches +---------------------------------- + +There is a major difference between + +:: + + $ git fetch REMOTE BRANCH + +and + +:: + + $ git fetch REMOTE BRANCH:BRANCH + +The first command fetches commits from the named BRANCH in the REMOTE +repository that are not in your repository and leaves the id (the +hash) of the head commit in file .git/FETCH_HEAD. But it doesn't +update any branch (doesn't move any label). + +The second command fetches commits from the named BRANCH in the REMOTE +repository that are not in your repository and updates both the local +branch BRANCH and its upstream remote branch. But it refuses to update +branches in case of non-fast-forward. And it refuses to update the +current branch. + +The first command is used internall by ``git pull``. + +:: + + $ git pull REMOTE BRANCH + +is equivalent to + +:: + + $ git fetch REMOTE BRANCH + $ git merge FETCH_HEAD # FETCH_HEAD is a literal here + +Certainly, BRANCH in that case should be your current branch. If you +want to merge a different branch into your current branch first update +that non-current branch and then merge:: + + $ git fetch origin v1:v1 # Update v1 + $ git pull --rebase origin v2 # Update the current branch v2 using + # rebase instead of merge + $ git merge v1 + Commit editing and caveats ==========================