orome
orome

Reputation: 48616

Failed push with bare Git repo

I have a remote bare repo master and a local branch cloud which I have set to track it with

git branch cloud -u amazon/master

but

git push

results in

fatal: The upstream branch of your current branch does not match the name of your current branch.

I've tried the solution suggested in a related question (which is, as near as I can tell, what I've done above), but it get the same error.

How I get configure tracking so that git push alone will push to the remote?


The relevant parts of my config:

[remote "amazon"]
        url = ssh://[email protected]/home/ubuntu/mlcode.git
        fetch = +refs/heads/*:refs/remotes/amazon/*
[branch "cloud"]
        remote = amazon
        merge = refs/heads/master

Upvotes: 1

Views: 417

Answers (1)

Greg Bacon
Greg Bacon

Reputation: 139701

Running

git config push.default upstream

will give you the desired behavior.

According to the git config documentation, the default behavior in version 2.0 is

  • simple - in centralized workflow, work like upstream with an added safety to refuse to push if the upstream branch’s name is different from the local one.

    When pushing to a remote that is different from the remote you normally pull from, work as current. This is the safest option and is suited for beginners.

In contrast, the upstream mode operates as follows.

  • upstream - push the current branch back to the branch whose changes are usually integrated into the current branch (which is called @{upstream}). This mode only makes sense if you are pushing to the same repository you would normally pull from (i.e., central workflow).

Working with a repository similar to yours

$ git branch
* cloud
  master

and nothing up my sleeve

$ git config --unset push.default

attempting to push gives the same error. Verbose mode (-v) is there so you can see what git is doing.

$ git push -v
fatal: The upstream branch of your current branch does not match
the name of your current branch.  To push to the upstream branch
on the remote, use

    git push amazon HEAD:master

To push to the branch of the same name on the remote, use

    git push amazon cloud

To choose either option permanently, see push.default in 'git help config'.

After a config change

$ git config push.default upstream

you get the behavior described in your question.

$ git push -v
Pushing to .../amazon/
To .../amazon/
 = [up to date]      cloud -> master
updating local tracking ref 'refs/remotes/amazon/master'
Everything up-to-date

Upvotes: 1

Related Questions