我创建了一个本地分支。如何将其推送到远程服务器?

更新:我在这里为Git2.0写了一个更简单的答案。


当前回答

你可以简单地,

git结帐-b YOUR-NEW-BRANCH-NAMEgit添加。git推送原点YOUR-NEW-BRANCH-NAME

您可以在相关git repo下看到您的分行代码

干杯!!:)

其他回答

如何通过源树进行操作

 1: Open SourceTree, click on Repository -> Checkout
 2: Click on Create New Branch
 3: Select the branch where you want to get code for new branch 
 4: Give your branch name
 5: Push the branch  (by click on Push-button)

你可以简单地,

git结帐-b YOUR-NEW-BRANCH-NAMEgit添加。git推送原点YOUR-NEW-BRANCH-NAME

您可以在相关git repo下看到您的分行代码

干杯!!:)

我知道这个问题得到了很好的回答,但我只想列出创建一个新分支“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

从Git2.37.0开始,您不再需要“--setupstreamorigin”。只要按一下。您可以通过启用push.autoSetupRemote选项来实现这一点

git-config--global--add--bool push.autoSetupRemote true

如果已使用--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