Skip to contentSkip to conversation

git push doesn't use local branch name as default

DISCUSSION Mathias Kunter 2 participants 2 messages May 27, 2021

lore
Share & tools
lore
#0 lore raw

Hi all,

at https://git-scm.com/docs/git-push#_description it says:

Quoted 6 lines

When neither the command-line nor the configuration specify what to push, the default behavior is used, which corresponds to the simple value for push.default: the current branch is pushed to the corresponding upstream branch, but as a safety measure, the push is aborted if the upstream branch does not have the same name as the local one.

However, on a branch which does *not* have an upstream branch configured, the command

Quoted 1 line

git push <remote_name>

doesn't use the local branch name as default, but fails with an error instead:

Quoted 4 lines

fatal: The current branch master has no upstream branch. To push the current branch and set the remote as upstream, use

git push --set-upstream <remote_name> master

Note that it *does* work if the remote branch name is explicitly specified:

Quoted 1 line

git push <remote_name> <branch_name>

But shouldn't this also work without having to explicitly specify the remote branch name, and default to the local branch name instead?

[System Info]
git version:
git version 2.31.1.windows.1
cpu: x86_64
built from commit: c5f0be26a7e3846e3b6268d1c6c4800d838c6bbb
sizeof-long: 4
sizeof-size_t: 8
shell-path: /bin/sh
feature: fsmonitor--daemon
uname: Windows 10.0 19042
compiler info: gnuc: 10.2
libc info: no libc information available
$SHELL (typically, interactive shell): <unset>

[Enabled Hooks]

#1 lore raw
Quoted 11 lines · Mathias Kunter

Hi all,

at https://git-scm.com/docs/git-push#_description it says:

Quoted 6 lines

When neither the command-line nor the configuration specify what to push, the default behavior is used, which corresponds to the simple value for push.default: the current branch is pushed to the corresponding upstream branch, but as a safety measure, the push is aborted if the upstream branch does not have the same name as the local one.

Quoted 6 lines

However, on a branch which does *not* have an upstream branch configured, the command

Quoted 1 line

git push <remote_name>

doesn't use the local branch name as default,

Yes it does, but only on the src side of the refspec. Something like:

git push <remote_name> <branch_name>:

(invalid refspec)

Note the remote side is missing, so git doesn't know where to push to.

Quoted 3 lines

Note that it *does* work if the remote branch name is explicitly specified:

Quoted 1 line

git push <remote_name> <branch_name>

In that case git assumes you mean <branch_name>:<branch_name>.

Sounds like you want to change the default to push.default=current.

Cheers.

Signature · 1 line
Felipe Contreras