Git 签出另一个分支
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11783813/
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
Git checkout another branch
提问by NoBugs
I run:
我跑:
git checkout mygithub/master
but for some reason, running 'git status' shows "not currently on any branch". Running:
但出于某种原因,运行 'git status' 显示“当前不在任何分支上”。跑步:
git checkout master
and then git status
, says that I'm now on branch master. Now I want to switch to another branch. Running git checkout anotherbranch
works, but git status
says I am still on branch 'master'. What am I doing wrong?
然后git status
,说我现在在分支主。现在我想切换到另一个分支。运行git checkout anotherbranch
有效,但git status
说我仍在分支“master”上。我究竟做错了什么?
回答by knittl
mygithub/master
is a remote branch. To create a local branch based off of that remote branch, you have to use git checkout -b mymaster mygithub/master
. Git tries to make this easy for you: if you write git checkout branchname
, and branchname only exists in a remote, but not locally, Git will automatically set up a local branch with <remote>/branchname
being its parent.
mygithub/master
是一个远程分支。要基于该远程分支创建本地分支,您必须使用git checkout -b mymaster mygithub/master
. Git 试图为您git checkout branchname
简化此操作:如果您编写, 并且 branchname 只存在于远程,而不是本地,Git 将自动设置一个本地分支,<remote>/branchname
并作为其父分支。
回答by Viru
If you want to switch to another branch then run this command:
如果要切换到另一个分支,请运行以下命令:
git checkout branch name
If you want to delete a branch then run this command:
如果要删除分支,请运行以下命令:
git branch -D branch name
If you want to create a new branch then run this command:
如果要创建新分支,请运行以下命令:
git checkout -b branch
回答by S.m.g. baquer
If you want to checkout from master branch just run this command in your terminal
如果您想从 master 分支结帐,只需在终端中运行此命令
git checkout -b BRANCH_NAME
git checkout -b BRANCH_NAME