Search code examples
gitbranchgit-push

Make current branch 'leo' push to the remote branch 'origin/leonardo_da_vinci'


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.


Solution

  • 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)".