git:切换分支而不分离头部 [英] git: switch branch without detaching head
问题描述
我在github上有一个主分支(主)和一个分支用于一些实验性工作。我做了一些提交并推送到实验分支,一切正常。
现在,在另一台机器上,我尝试克隆我的存储库(git clone repository )然后切换到实验分支(git checkout
我是git的新手,所以我对不起,如果我是一个白痴,但我找不到任何文件,这将帮助我重新贴上我的头。
编辑
跟踪分支的概念就是我所缺少的。现在我对这个概念有了一个清晰的认识。就个人而言,我发现 感谢您的帮助! 为了方便,你可以使用相同的字符串作为localname& branchname 您必须首先在本地进行远程分支追踪,以便切换并处理它。 I have a repository on github with a main branch (master) and a branch for some experimental work. I made some commits and pushed to the experimental branch and everything was fine. Now, on a different machine, I try to clone my repository (git clone repository) and then switch to the experimental branch (git checkout branchname) but every time I do this my head gets detached and I can't push my changes. What am I doing wrong? I get the feeling I'm missing a fundamental git concept someplace but reading random git man pages isn't giving me any clues. I'm new to git so I'm sorry if I'm being an idiot but I can't find anything in the docs that will help me reattach my head. EDIT The concept of a tracking branch is what I was missing. Now that I grok that concept everything is clear. Personally, I find the Thanks for the help! For convenience, you may use the same string for localname & branchname If you have colours enabled, local branches will be one colour, and remote another. You have to first make a remote branch tracked locally in order to be able to switch-to and work on it. 这篇关于git:切换分支而不分离头部的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋! git branch --track
语法比 git checkout -b branch-name origin / branch-name <
#第一次:make origin / branchname本地作为本地名称提供
git checkout -b本地名称origin / branchname
#其他情况
git checkout localname
git push origin
当您签出 origin / branchname
时,您并未真正检查分支。
origin / branchname
是一个远程名称,您可以使用
<$如果你启用了颜色,本地分支机构将是一种颜色,而另一种则偏远。
git branch --track
syntax to be much more intuitive than git checkout -b branch-name origin/branch-name
.# first time: make origin/branchname locally available as localname
git checkout -b localname origin/branchname
# othertimes
git checkout localname
git push origin
When you checked out origin/branchname
you weren't really checking out a branch.
origin/branchname
is a "remote" name, and you can get a list of them with branch -a