我创建了一个本地分支。如何将其推送到远程服务器?
更新:我写了一个simpler answer for Git 2.0 here .
最佳答案
首先,创建一个新的本地分支并检查它:
git checkout -b <branch-name>
当你将它推送到远程服务器时,远程分支会自动创建:
git push <remote-name> <branch-name>
<remote-name>
通常是 origin
,这是 git 给你从中克隆的远程的名称。然后,您的同事可能会简单地 pull 该分支。
但是请注意,正式的格式是:
git push <remote-name> <local-branch-name>:<remote-branch-name>
但是当您省略一个时,它会假定两个分支名称相同。话虽如此,作为警告的话,不要犯仅指定 :<remote-branch-name>
的严重错误。 (带冒号),否则远程分支将被删除!
以便后续git pull
将知道该怎么做,您可能想使用:
git push --set-upstream <remote-name> <local-branch-name>
如下所述,--set-upstream
选项设置一个上游分支:
For every branch that is up to date or successfully pushed, add upstream (tracking) reference, used by argument-less git-pull(1) and other commands.
关于git - 如何创建远程 Git 分支?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1519006/