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

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


当前回答

我用这个,它很方便:

git config --global alias.mkdir '!git checkout -b $1; git status; git push -u origin $1; exit;'

用法:git mkdir NEW_BRANCH

你甚至不需要git状态;也许,我只是想确保一切顺利。。。

您可以通过一个命令同时拥有LOCAL和REMOTE分支。

其他回答

如果要从当前分支创建分支

git checkout -b {your_local_branch_name}

如果您想要远程分支的分支,可以尝试

git checkout -b {your_local_branch_name} origin/<remote_branch_name>

如果完成了更改,则可以添加文件。

git add -A or git add <each_file_names>

然后在本地提交

git commit -m 'your commit message'

当您想推送到远程回购时

git push -u origin <your_local_branch_name>

所有人都将

git checkout -b bug_fixes 

或如果要从远程分支创建本地分支bug_fixes,请说development

git checkout -b bug_fixes origin/development

您可以通过

git push -u origin bug_fixes

任何时候你想从任何其他分支更新你的分支,比如master,

git pull origin master

如何通过源树进行操作

 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)

如果新创建的分支不是从同一个repo派生的,即如果您没有使用gitcheckout-b newbranch创建新分支,则gitpush-u<remotename><branch name>不起作用。

例如,我在本地克隆了两个不同的存储库,我必须将repo2/branch1复制到repo1/,然后再将其推送。

此链接帮助我将本地分支(从另一个回购中克隆)推送到远程回购:

如果已使用--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 config --global alias.mkdir '!git checkout -b $1; git status; git push -u origin $1; exit;'

用法:git mkdir NEW_BRANCH

你甚至不需要git状态;也许,我只是想确保一切顺利。。。

您可以通过一个命令同时拥有LOCAL和REMOTE分支。