将所有本地分支推送到 git 中的 origin

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/23892037/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 18:07:50  来源:igfitidea点击:

Push all local branches to origin in git

git

提问by Napolux

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

假设我的 git 中有很多本地分支没有推送到远程存储库。

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

如何使用单个命令将所有这些都推送到原点?

回答by Fredszaq

Have you tried

你有没有尝试过

git push --all -u 

The git man states

git man 说

--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,

- 全部

不是将每个引用命名为推送,而是指定推送 refs/heads/ 下的所有引用。

-u, --set-upstream

对于每个最新或成功推送的分支,添加上游(跟踪)引用,

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

-u,如果你打算从这些分支后拉是有用

回答by gravetii

git push <remote_name> '*:*'

The command is intuitive in that it specifies the :. The one on the left of :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_branchyou will have a remote branch named <remote_name>/my_branch.

*:*告诉混帐要每个地方分支推送到远程与远程相同的名称。因此,如果您有一个名为的分支,my_branch您将有一个名为<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 -rwhich will show you all the remote branches.

所以通常你会这样做git push origin '*:*',你会在远程找到每个具有相同名称的本地分支,你可以确认git branch -r它会显示所有远程分支。

回答by lrineau

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

您可以使用refspec告诉 git 推送所有分支:

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