我创建了一个本地分支。如何将其推送到远程服务器?
更新:我在这里为Git2.0写了一个更简单的答案。
我创建了一个本地分支。如何将其推送到远程服务器?
更新:我在这里为Git2.0写了一个更简单的答案。
当前回答
这里有一个例子,我只有两个分支首先是本地的:起源和移动测试。
直到我在命令行中使用它来实际显示远程分支中更新的文件时,我才开始工作。
git push --set-upstream origin mobile-test
其他回答
首先在本地创建分支:
git checkout -b your_branch
然后远程创建分支:
git push --set-upstream origin your_branch
注意:这适用于git的最新版本:
$ git --version
git version 2.3.0
干杯
现在使用git,当您在正确的分支中时,您只需键入
git push—设置上游起点<远程分支名称>
git为您创建原始分支。
我知道这个问题得到了很好的回答,但我只想列出创建一个新分支“myNewBranch”并推送到远程(在我的情况下是“源”)并设置跟踪所采取的步骤。将其视为“TL;DR”版本:)
# create new branch and checkout that branch
git checkout -b myNewBranch
# now push branch to remote
git push origin myNewBranch
# set up the new branch to track remote branch from origin
git branch --set-upstream-to=origin/myNewBranch myNewBranch
如果已使用--single branch克隆当前分支,请使用此命令从当前分支创建新分支:
git checkout -b <new-branch-name>
git push -u origin <new-branch-name>
git remote set-branches origin --add <new-branch-name>
git fetch
我只是想在以下时间添加:
git checkout -b {branchName}
创建一个新分支,它也会检出该分支/使其成为当前分支。如果出于某种原因,您只想捕捉一个分支,而不想将其作为当前分支,则可以使用以下命令:
git branch {branchName}
在第一个命令中,“checkout”使所述分支成为当前分支,“-b”表示:该分支还不存在,所以请为我创建。