Skip to content

Commit 0ec629d

Browse files
committed
doc: add an UPSTREAM BRANCHES section to pull/push/fetch
From user feedback: one user mentioned that they don't know what the term "upstream branch" means. As far as I can tell, the most complete description is under the `--track` option in `git branch`. Upstreams are an important concept in Git and the `git branch` man page is not an obvious place for that information to live. There's also a very terse description of "upstream branch" in the glossary that's missing a lot of key information, like the fact that the upstream is used by `git status` and `git pull`, as well as a description in `git-config` in `branch.<name>.remote` which doesn't explain the relationship to `git status` either. Since the `git pull`, `git push`, and `git fetch` man pages already include sections on REMOTES and the syntax for URLs, add a section on UPSTREAM BRANCHES to `urls-remotes.adoc` and rename it to `urls-remotes-upstreams.adoc`. That's an awkward name but at least it's clear what's in the file. In the new UPSTREAM BRANCHES section, cover the various ways that upstreams branches are automatically set in Git, since users may mistakenly think that their branch does not have an upstream branch if they didn't explicitly set one. A terminology note: Git uses two terms for this concept: - "tracking" as in "the current branch is _tracking_ some remote" or the `--track` option to `git branch` - "upstream" or "upstream branch", as in `git push --set-upstream`. This term is also used in the `git rebase` man page to refer to the first argument to `git rebase`, as well as in `git pull` to refer to the branch which is going to be merged into the current branch ("merge the upstream branch into the current branch") Use "upstream branch" as a heading for this concept even though the term "upstream branch" is not always used strictly in the sense of "the tracking information for the current branch". "Upstream" is used much more often than "tracking" in the Git docs to refer to this concept and the goal is to help users understand the docs. Signed-off-by: Julia Evans <[email protected]>
1 parent 270edd2 commit 0ec629d

File tree

4 files changed

+41
-6
lines changed

4 files changed

+41
-6
lines changed

Documentation/git-fetch.adoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ include::pull-fetch-param.adoc[]
5252
Read refspecs, one per line, from stdin in addition to those provided
5353
as arguments. The "tag <name>" format is not supported.
5454

55-
include::urls-remotes.adoc[]
55+
include::urls-remotes-upstreams.adoc[]
5656

5757

5858
CONFIGURED REMOTE-TRACKING BRANCHES[[CRTB]]

Documentation/git-pull.adoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ include::fetch-options.adoc[]
140140

141141
include::pull-fetch-param.adoc[]
142142

143-
include::urls-remotes.adoc[]
143+
include::urls-remotes-upstreams.adoc[]
144144

145145
include::merge-strategies.adoc[]
146146

Documentation/git-push.adoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -431,7 +431,7 @@ further recursion will occur. In this case, "only" is treated as "on-demand".
431431
--ipv6::
432432
Use IPv6 addresses only, ignoring IPv4 addresses.
433433

434-
include::urls-remotes.adoc[]
434+
include::urls-remotes-upstreams.adoc[]
435435

436436
OUTPUT
437437
------

Documentation/urls-remotes.adoc renamed to Documentation/urls-remotes-upstreams.adoc

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,41 @@ git push uses:
9191
HEAD:refs/heads/<head>
9292
------------
9393

94-
95-
96-
94+
UPSTREAM BRANCHES[[UPSTREAM-BRANCHES]]
95+
--------------------------------------
96+
97+
Branches in Git can optionally have an upstream remote branch.
98+
Git defaults to using the upstream branch for remote operations, for example:
99+
100+
* It's the default for `git pull` or `git fetch` with no arguments
101+
* It's sometimes the default for `git push` with no arguments. See the
102+
`push.default` section of linkgit:git-config[1] for the details.
103+
* `git status` and `git branch -v` will show the
104+
relationship between the current branch and the upstream,
105+
for example "Your branch is up to date with origin/main"
106+
107+
The upstream is stored in `.git/config`, in the "remote" and "merge"
108+
fields. For example, if `main`'s upstream is `origin/main`:
109+
110+
```
111+
[branch "main"]
112+
remote = origin
113+
merge = refs/heads/main
114+
```
115+
116+
You can set an upstream branch explicitly with
117+
`git push --set-upstream <remote> <branch>` or `git branch --track`,
118+
but Git will often automatically set the upstream for you, for example:
119+
120+
* When you clone a repository, Git will automatically set the upstream
121+
for the default branch.
122+
* If you have the `push.autoSetupRemote` configuration option set,
123+
`git push` will automatically set the upstream the first time you push
124+
a branch.
125+
* Checking out a remote-tracking branch with `git checkout <branch>`
126+
will automatically create a local branch with that name and set
127+
the upstream to the remote branch.
128+
129+
[NOTE]
130+
Upstream branches are sometimes referred to as "tracking information",
131+
as in "set the branch's tracking information".

0 commit comments

Comments
 (0)