我创建了一个本地分支。如何将其推送到远程服务器?
更新:我在这里为Git2.0写了一个更简单的答案。
我创建了一个本地分支。如何将其推送到远程服务器?
更新:我在这里为Git2.0写了一个更简单的答案。
当前回答
你可以简单地,
git结帐-b YOUR-NEW-BRANCH-NAMEgit添加。git推送原点YOUR-NEW-BRANCH-NAME
您可以在相关git repo下看到您的分行代码
干杯!!:)
其他回答
如果要从当前分支创建分支
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
如果新创建的分支不是从同一个repo派生的,即如果您没有使用gitcheckout-b newbranch创建新分支,则gitpush-u<remotename><branch name>不起作用。
例如,我在本地克隆了两个不同的存储库,我必须将repo2/branch1复制到repo1/,然后再将其推送。
此链接帮助我将本地分支(从另一个回购中克隆)推送到远程回购:
我使用了两种方法来创建分支
如果您正在使用TortoiseGit,请执行以下步骤:-
1.使用TortoiseGit创建分支
右键单击您的项目>>TortoiseGit>>创建分支>>编写分支的名称并选择基本分支,然后按ok
2.推动分支
右键单击项目>>TortoiseGit>>推送>>单击确定
3.切换到新分支
右键单击您的项目>>TortoiseGit>>切换/签出>>选择新创建的分支并按ok
如果使用命令提示符,请执行以下步骤:-
1.使用命令提示符创建分支
$git签出-b new_branch_name
2.推动分支
$git推送原点new_branch_name
3.切换到新分支它已经切换为new_branch_name,否则您可以使用
$git签出new_branch_name
最简单的解决方案。。。鼓卷。。。git版本2.10.1(Apple git-78)
1) git checkout -b localBranchNameThatDoesNotExistInRemote
2) Do your changes, and do a git commit
3) git push origin localBranchNameThatDoesNotExistInRemote --force
注意:您刚刚在本地环境中创建的分支和您尝试推送的远程非现有分支必须具有相同的名称。
如果已使用--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