Push all local branches to origin in git [duplicate]

匿名 (未验证) 提交于 2019-12-03 02:14:01

问题:

This question already has an answer here:

Let's say that I have A LOT of local branches in my git not pushed on the remote repository.

How can I push all of them to origin with a single command?

回答1:

Have you tried

git push --all -u 

The git man states

--all

Instead of naming each ref to push, specifies that all refs under refs/heads/ be pushed.

-u, --set-upstream

For every branch that is up to date or successfully pushed, add upstream (tracking) reference,

the -u is useful if you intent to pull from these branches later



回答2:

git push <remote_name> '*:*'

The command is intuitive in that it specifies the :. The one on the left on : indicates the name of the local branch and the one on the right specifies the remote branch. In your case, we want to map with the same name and thus the command.

The *:* tells git that you want to push every local branch to remote with the same name on remote. Thus if you have a branch named my_branch you will have a remote branch named <remote_name>/my_branch.

So typically you would do git push origin '*:*' and you would find every local branch with the same name in the remote, which you can confirm by git branch -r which will show you all the remote branches.



回答3:

You can use a refspec that tells git to push all your branches:

git push origin 'refs/heads/*:refs/heads/*'


标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!