git 如何在本地和远程创建一个新分支?通用电气
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/33546137/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to create a new branch on both local and remote? GIT
提问by chipbk10
I create a new branch like this:
我创建了一个这样的新分支:
git branch dev-itt-9
However, it only creates a new branch on local
但是,它只会在本地创建一个新分支
git branch -a * dev-itt-9 master testing remotes/origin/HEAD -> origin/master remotes/origin/development remotes/origin/master remotes/origin/testing
What is the proper way to create a new branch on both local and remote?
在本地和远程创建新分支的正确方法是什么?
I am quite new to git. Sorry if my question is stupid.
我对 git 很陌生。对不起,如果我的问题很愚蠢。
回答by Deepak Biswal
First, you create your branch locally:
首先,在本地创建分支:
git checkout -b <branch-name>
The remote branch is automatically created when you push it to the remote server. So when you feel ready for it, you can just do:
当您将其推送到远程服务器时,会自动创建远程分支。因此,当您准备好迎接它时,您可以这样做:
git push <remote-name> <branch-name>
Where <remote-name>
is typically origin
, the name which git gives to the remote you cloned from. Your colleagues would then just pull that branch, and it's automatically created locally.
哪里<remote-name>
通常是origin
git 为您克隆的远程设备提供的名称。然后你的同事会拉那个分支,它会在本地自动创建。
回答by Chris Maes
Suppose you already created your local branch (using git branch <branch-name>
or git checkout -b <branch-name>
, you can use:
假设您已经创建了本地分支(使用git branch <branch-name>
或git checkout -b <branch-name>
,您可以使用:
git push -u origin <branch-name>
explications:
说明:
-u
=--set-upstream
: set this new remote branch as tracking branch.origin
: the name of your remote repository
-u
=--set-upstream
: 将此新的远程分支设置为跟踪分支。origin
: 远程仓库的名称