1

Situation:

  • Remote repository has branch leonardo_da_vinci
  • Your local repository has branch leo

In the local repository, I want to push leo <-> leonardo_da_vinci with the command git push origin (no following leo:... because I forget this). How?

You can easily do it with git push origin leo:leonardo_da_vinci, but how to config git to use git push?

I tried using --set-upstream-to, --track, and adding to .git/config the line push = refs/head/leo:leonardo_da_vinci into branch leo section. No luck.

Here is .git/config:

[core]
    repositoryformatversion = 0
    filemode = true
    bare = false
    logallrefupdates = true
[remote "origin"]
    url = /some_url/
    fetch = +refs/heads/*:refs/remotes/origin/*
[branch "master"]
    remote = origin
    merge = refs/heads/master
[branch "leo"]
    remote = origin
    merge = refs/heads/leonardo_da_vinci
[branch "origin/leonardo_da_vinci"]
    remote = .
    merge = refs/heads/leo

My git config has push.default set to simple.

Ayrat
  • 1,221
  • 1
  • 18
  • 36

1 Answers1

1

if the branch leo is the one checked out, a simple git push will be enough, because the upstream branch leonardo_da_vinci has been set (with git branch -u, or after the first git push -u origin leonardo_da_vinci)

If you would need at least git push origin leo.

But not git push leo, as the first parameter of git push is the remote, not the branch.

Make sure that git config push.default is set to upstream.
See "git - push current vs. push upstream (tracking)".

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • hm, i will try using `git branch -u` again, somehow this didn't work before -- command `git push origin` resulted in pushing _new_ branch `leo` into remote repo, instead of pushing changes into `leonardo_da_vinci`. (yes, even after the first `push` was with `u` option. – Ayrat Sep 18 '15 at 11:32
  • @Ayrat Then try `git checkout leo; git push -u origin leo leonardo_da_vinci`; then future `git push` will work. – VonC Sep 18 '15 at 11:34
  • No, it does not work. Git says: `fatal: The upstream branch of your current branch does not match the name of your current branch...`, and suggests using `git push origin leo:leonardo_da_vinci` syntax. [Here](http://stackoverflow.com/a/24865780/801203) is suggested to rename the local branch. May be the only solution. – Ayrat Sep 18 '15 at 11:50
  • 1
    @Ayrat that because of the push.default policy. See http://stackoverflow.com/a/17045911/6309 and set it to 'upstream". – VonC Sep 18 '15 at 11:52