Skip to content

Commit dd5e578

Browse files
committed
Merge branch 'je/doc-push-upstream' into jch
Documentation updates. * je/doc-push-upstream: SQUASH??? doc: git-push: add explanation of `git push origin main` doc: git-push: clarify "what to push" doc: git-push: clarify "where to push" doc: add an UPSTREAM BRANCHES section to pull/push/fetch doc: git-push: clarify intro
2 parents 39d45c5 + 5514bf8 commit dd5e578

File tree

2 files changed

+68
-24
lines changed

2 files changed

+68
-24
lines changed

Documentation/git-push.adoc

Lines changed: 27 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -19,30 +19,35 @@ SYNOPSIS
1919
DESCRIPTION
2020
-----------
2121

22-
Updates remote refs using local refs, while sending objects
23-
necessary to complete the given refs.
22+
Updates one or more branches, tags, or other references in a remote
23+
repository from your local repository, and sends all necessary data
24+
that isn't already on the remote.
2425

25-
You can make interesting things happen to a repository
26-
every time you push into it, by setting up 'hooks' there. See
27-
documentation for linkgit:git-receive-pack[1].
26+
The simplest way to push is `git push <remote> <branch>`.
27+
`git push origin main` will push the local `main` branch to the `main`
28+
branch on the remote named `origin`.
29+
30+
The `<repository>` argument defaults to the upstream for the current branch,
31+
or `origin` if there's no configured upstream.
2832

29-
When the command line does not specify where to push with the
30-
`<repository>` argument, `branch.*.remote` configuration for the
31-
current branch is consulted to determine where to push. If the
32-
configuration is missing, it defaults to 'origin'.
33+
To decide which branches, tags, or other refs to push, Git uses
34+
(in order of precedence):
3335

34-
When the command line does not specify what to push with `<refspec>...`
35-
arguments or `--all`, `--mirror`, `--tags` options, the command finds
36-
the default `<refspec>` by consulting `remote.*.push` configuration,
37-
and if it is not found, honors `push.default` configuration to decide
38-
what to push (See linkgit:git-config[1] for the meaning of `push.default`).
36+
1. The `<refspec>` argument(s) (for example `main` in `git push origin main`)
37+
or the `--all`, `--mirror`, or `--tags` options
38+
2. The `remote.*.push` configuration for the repository being pushed to
39+
3. The `push.default` configuration. The default is `push.default=simple`,
40+
which will push to a branch with the same name as the current branch.
41+
See the <<CONFIGURATION,CONFIGURATION>> section below for more on `push.default`.
3942
40-
When neither the command-line nor the configuration specifies what to
41-
push, the default behavior is used, which corresponds to the `simple`
42-
value for `push.default`: the current branch is pushed to the
43-
corresponding upstream branch, but as a safety measure, the push is
44-
aborted if the upstream branch does not have the same name as the
45-
local one.
43+
`git push` may fail if you haven't set an upstream for the current branch,
44+
depending on what `push.default` is set to.
45+
See the <<UPSTREAM-BRANCHES,UPSTREAM BRANCHES>> section below for more
46+
on how to set and use upstreams.
47+
48+
You can make interesting things happen to a repository
49+
every time you push into it, by setting up 'hooks' there. See
50+
documentation for linkgit:git-receive-pack[1].
4651

4752

4853
OPTIONS[[OPTIONS]]
@@ -710,8 +715,8 @@ a `git gc` command on the origin repository.
710715
711716
include::transfer-data-leaks.adoc[]
712717
713-
CONFIGURATION
714-
-------------
718+
CONFIGURATION[[CONFIGURATION]]
719+
------------------------------
715720

716721
include::includes/cmd-config-section-all.adoc[]
717722

Documentation/urls-remotes.adoc

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,5 +92,44 @@ git push uses:
9292
------------
9393

9494

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

0 commit comments

Comments
 (0)