Skip to content

Commit 10a9718

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`. 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 tracking information for the 'foo' branch" 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 4811ce1 commit 10a9718

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

Documentation/urls-remotes.adoc

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,5 +92,47 @@ git push uses:
9292
------------
9393

9494

95+
[[UPSTREAM-BRANCHES]]
96+
UPSTREAM BRANCHES
97+
-----------------
98+
99+
Branches in Git can optionally have an upstream remote branch.
100+
Git defaults to using the upstream branch for remote operations, for example:
101+
102+
* It's the default for `git pull` or `git fetch` with no arguments.
103+
* It's the default for `git push` with no arguments, with some exceptions.
104+
For example, you can use the `branch.<name>.pushRemote` option to push
105+
to a different remote than you pull from, and by default with
106+
`push.default=simple` the upstream branch you configure must have
107+
the same name.
108+
* Various commands, including `git checkout` and `git status`, will
109+
show you how many commits have been added to your current branch and
110+
the upstream since you forked from it, for example "Your branch and
111+
'origin/main' have diverged, and have 2 and 3 different commits each
112+
respectively".
113+
114+
The upstream is stored in `.git/config`, in the "remote" and "merge"
115+
fields. For example, if `main`'s upstream is `origin/main`:
95116
117+
------------
118+
[branch "main"]
119+
remote = origin
120+
merge = refs/heads/main
121+
------------
96122
123+
You can set an upstream branch explicitly with
124+
`git push --set-upstream <remote> <branch>`
125+
but Git will often automatically set the upstream for you, for example:
126+
127+
* When you clone a repository, Git will automatically set the upstream
128+
for the default branch.
129+
* If you have the `push.autoSetupRemote` configuration option set,
130+
`git push` will automatically set the upstream the first time you push
131+
a branch.
132+
* Checking out a remote-tracking branch with `git checkout <branch>`
133+
will automatically create a local branch with that name and set
134+
the upstream to the remote branch.
135+
136+
[NOTE]
137+
Upstream branches are sometimes referred to as "tracking information",
138+
as in "set the branch's tracking information".

0 commit comments

Comments
 (0)