通过终端的 GIT 结帐分支

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/41049615/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 12:29:01  来源:igfitidea点击:

GIT checkout branch via terminal

gitgithub

提问by CyberJunkie

Is it possible to checkout a branch using the command line (terminal on mac) knowing just:

是否可以使用命令行(mac 上的终端)签出分支,只知道:

ssh://[email protected]:8000/abc/somename.git

回答by David Katona

You have to clone this repository first using

您必须首先使用克隆此存储库

git clone ssh://[email protected]:8000/abc/somename.git

This will be creating a local working copy of this project and will be on the default branch of it what is probably 'master'

这将创建该项目的本地工作副本,并将位于它的默认分支上,可能是“主”

You can verify which branch you are on using

您可以验证您使用的是哪个分支

git status

If you want a list of the available branches (in the remote repo) execute

如果你想要一个可用分支列表(在远程仓库中)执行

git branch -r

If you want another remote branch available on your local copy you can use

如果您想在本地副本上使用另一个远程分支,您可以使用

git checkout --track origin/remotebranchname

The --track parameter will tie your local branch and remote branch together so you won't have to be give it explicitly when pushing your code for example.

--track 参数会将您的本地分支和远程分支联系在一起,因此例如在推送代码时您不必明确给出它。

回答by Specter

Create the branch on your local machine and switch in this branch :

在本地机器上创建分支并切换到此分支:

$ git checkout -b [name_of_your_new_branch] [name_of_the_origin_branch]

$ git checkout -b [name_of_your_new_branch] [name_of_the_origin_branch]