Defaults to git push

Viewed 37

I do push to two remote repositories when I do git commit all

[core]
        repositoryformatversion = 0
        filemode = false
        bare = false
        logallrefupdates = true
        symlinks = false
        ignorecase = true
[remote "origin"]
        url = git@bitbucket.org:kkk_pro/tst1.git
        fetch = +refs/heads/*:refs/remotes/origin/*
[branch "master"]
        remote = origin
        merge = refs/heads/master
[remote "all"]
        url = git@bitbucket.org:kkk_pro/tst2.git
        fetch = +refs/heads/*:refs/remotes/all/*
        pushurl = git@bitbucket.org:kkk_pro/tst1.git
        pushurl = git@bitbucket.org:kkk_pro/tst2.git

But when I type git push git pushes only to tst1 ? Why? How to ask git to use all as default remote?

2 Answers

But when I type git push git pushes only to tst1


How does git decide where to push the code?

Prior to Git version 2 everytime you ececuted git push without specifiying remote all your local branches have been pushed to the remote.

Starting in git v2 you need to specify the origin and the remote whenever you pushed.

Whenever you type git push without remote & branch git will push the branch to the default upstream branch.

You can set the default branch on the remote for the push using:

git push --set-upstream <origin> <branch>

enter image description here

From your config:

[branch "master"]
    remote = origin

You can see that your master is set to be pushed to origin whih is tst1

How to add multiple push urls?

git remote set-url --add --push <origin_name> git@github.com:.../a.git
git remote set-url --add --push <origin_name> git@github.com:.../b.git

How to view the configuration?

git remote show origin 

enter image description here

origin is the default remote, just move it there.

From the docs:

When the command line does not specify where to push with the argument, branch.*.remote configuration for the current branch is consulted to determine where to push. If the configuration is missing, it defaults to origin.

Related