我创建了一个本地分支。如何将其推送到远程服务器?
更新:我在这里为Git2.0写了一个更简单的答案。
我创建了一个本地分支。如何将其推送到远程服务器?
更新:我在这里为Git2.0写了一个更简单的答案。
当前回答
基于当前分支在本地创建新分支:
git checkout -b newbranch
按正常方式提交任何更改。然后,将其向上推:
git push -u origin HEAD
这是一个快捷方式,可以将当前分支推送到原点上同名的分支并跟踪它,这样以后就不需要指定原点HEAD了。
其他回答
如何通过源树进行操作
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 push <remote-name> <local-branch-name>:<remote-branch-name>
足以推动本地分支。
您的同事可以使用以下命令拉动所有远程分支(包括新分支):
git remote update
然后,要对分支进行更改,通常的流程如下:
git checkout -b <local-branch-name> <remote-name>/<remote-branch-name>
如果要从当前分支创建分支
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
从Git2.37.0开始,您不再需要“--setupstreamorigin”。只要按一下。您可以通过启用push.autoSetupRemote选项来实现这一点
git-config--global--add--bool push.autoSetupRemote true
首先,必须在本地创建分支
git checkout -b your_branch
之后,您可以在分支中本地工作,当您准备好共享该分支时,将其推送
git push -u origin your_branch
队友可以通过以下方式到达你的分支:
git fetch
git checkout origin/your_branch
您可以继续在分支中工作,并随时进行推送,而无需将参数传递给gitpush(无参数gitpush会将主节点推送到远程主节点,将您的本地分支推送到远程您的分支,等等)
git push
团队成员可以通过执行提交推送到您的分支,然后显式推送
... work ...
git commit
... work ...
git commit
git push origin HEAD:refs/heads/your_branch
或者跟踪分支以避免gitpush的参数
git checkout --track -b your_branch origin/your_branch
... work ...
git commit
... work ...
git commit
git push