1

I have a directory containing some files. I initialized it as a git repository using

git init

I added the current files and committed them to empty repository using

git add .
git commit -m <Message>

Now i added the remote named origin

git remote add origin <remote url>

At this point, i remembered that my remote repository already had some code and hence it would have been better to merge them. So i checked out another branch with current code as

git checkout development

Now i intended to pull remote code in my master and then merge development branch (containing local code) into the master. However when i tried doing

git checkout origin/master

in my master branch then i got a message that HEAD is detached. I am not sure how did this happen.

It would be great if someone could explain why did this happen.

Any help is appreciated. Thanks.

harsrawa
  • 422
  • 5
  • 18
  • Yes this is explained in that answer. I got the workaround but i am little confused. If i am checking out the remote branch then should all the local changes be overridden with remote content ? If so then my head pointing at origin/master commit would be the correct one. – harsrawa Oct 21 '16 at 20:43
  • After you've checked out the remote branch, your working tree reflects the commit that `origin/master` points to, yes. However, `HEAD` then points to the commit that `origin/master` points to. `HEAD` cannot point to a remote-tracking branch; only to a normal branch, or to a commit directly. In the latter case, you're in detached-HEAD state. – jub0bs Oct 21 '16 at 20:53
  • 1
    You explained this very beautifully. I think this bit was missing in the other answer. Thanks ! – harsrawa Oct 21 '16 at 20:57
  • I'll add the missing bit to the other answer. – jub0bs Oct 21 '16 at 21:01

0 Answers0