假设我有以下分支
refs/heads/master
refs/heads/x
refs/heads/y
...
refs/heads/features/a
refs/heads/features/b
refs/heads/features/c
refs/heads/features/d
..
现在我想将位于 refs/heads/features/*
中的所有分支推送到另一个远程(我已经配置过),以便它们最终以相同的名称出现在远程上。但我不想x
和y
。这可能吗?如果是的话,我该如何对标签做同样的事情?
我知道可以使用git push --all
,但它不完全是我想要的。
最佳答案
您可以使用 glob 配置 refspec。
git push <remote_name> 'refs/heads/features/*:refs/heads/features/*'
如果您希望强制推送所有分支,请在 refspec 前面加上 +
。如果您想配置始终默认推送特定远程的引用规范,那么您可以在本地 .git/config
中配置它。使用以下命令。
git config --add remote.<remote_name>.push 'refs/heads/features/*:refs/heads/features/*'
现在当git push <remote_name>
使用时无需附加参数,默认情况下它将使用该 refspec。
这又是一个通过强制推送来推送到 Remote 的示例。
git push <remote_name> '+refs/heads/features/*:refs/heads/features/*'
关于git - 将与给定引用规范匹配的多个分支或标签一步推到另一个远程,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25265948/