Skip to content

Commit b5676f5

Browse files
committed
add to upstream and add a short pulling section
1 parent 0bc490b commit b5676f5

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

book/03-git-branching/1-git-branching.asc

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -743,6 +743,28 @@ Switched to a new branch 'sf'
743743
----
744744

745745
Now, your local branch sf will automatically push to and pull from origin/serverfix.
746+
If you already have a local branch and want to set it to a remote branch you just pulled down, or want to change the upstream branch you're tracking, you can use the `-u` or `--set-upstream-to` option to `git branch` to explicitly set it at any time.
747+
748+
[source,shell]
749+
----
750+
$ git branch -u origin/serverfix
751+
Branch serverfix set up to track remote branch serverfix from origin.
752+
----
753+
754+
[NOTE]
755+
.Upstream shorthand
756+
====
757+
When you have an tracking branch set up, you can reference it with the `@{upstream}` or `@{u}` shorthand. So if you're on the `master` branch and it's tracking `origin/master`, you can say something like `git merge @{u}` instead of `git merge origin/master` if you wish.
758+
====
759+
760+
==== Pulling
761+
762+
While the `git fetch` command will fetch down all the changes on the server that you don't have yet, it will not modify your working directory at all.
763+
It will simply get the data for you and let you merge it yourself.
764+
However, there is a command called `git pull` which is essentially a `git fetch` immediately followed by a `git merge` in most cases.
765+
If you have a tracking branch set up as demonstrated in the last section, either by explicitly setting it or by having it created for you by the `clone` or `checkout` commands, `git pull` will look up what server and branch your current branch is tracking, fetch from that server and then try to merge in that remote branch.
766+
767+
There are other uses of the `pull` command that we'll address in [[_git_tools]], but generally it's better to simply use the `fetch` and `merge` commands explicitly as the magic of `git pull` can often be confusing.
746768

747769
==== Deleting Remote Branches
748770

0 commit comments

Comments
 (0)