Switch to a remote branch getting detached head [duplicate]

笑着哭i 提交于 2019-12-10 13:55:50

问题


Here is a list of all my branches:

$ git branch -a
* temp
  remotes/heroku/master
  remotes/origin/dev
  remotes/origin/master

When I type git checkout remotes/origin/master to switch to my origin master branch, Git switches to a detached HEAD state. Why?


回答1:


This is the right behavior since you have checked out the remote branch.

If you wish to check out master and work on it you should do this now:

# checkout remote branch as local branch
# this will look up the branch name locally and if it does not find it it
#will checkout your remote branch with this name.
git checkout master

When you checkout remote branch you are simply pointing your HEAD to the latest commit from this branch. If you wish to work on it you have to check it out as local branch without the remote/<branch>. This will automatically checkout and create local branch with the given name.

If you wish to learn more about the HEAD read all about it here.


What is a detached HEAD?

A detached HEAD mean that your HEAD point to a commit which is not the lates in the commit chain.

In this sample commit #4 is the latest while the HEAD is pointing to commit #2.



来源:https://stackoverflow.com/questions/35301931/switch-to-a-remote-branch-getting-detached-head

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!