I have downloaded a git repository some time ago and continued to work on that locally. I was making some changes and occasionally committed them locally. I haven't pushed any changes either. The last time I tried to commit I found a message (in pyCharm but I guess it's a generic message). I am not sure what I have done to wreck chaos to my repository.
Anyway the message was:
The Git repository ...\PycharmProjects\tensorflow1\deeplab is in the detached HEAD state. You can look around, make experimental changes and commit them, but be sure to checkout a branch not to lose your work. Otherwise you risk losing your changes.
As I am not familiar with all git jargon I was a bit alarmed about the message. As far as I understand checkout will give me a version of the remote git repository to work with, right? I just want to have a committed local version so checkout is not what I would want, right?
To make it clear, I am not interested in getting any newer version of the original git repository. I just want to work with my local version. So, local commits suit me fine.
My conclusion is that:
- I should not checkout any version and
- Local commits are safe (even in this detached HEAD state) for my case.
Also, if the above are correct, how can I avoid this detached HEAD state? I should create a new branch of my local git repository and work with that one?
Edit:
After a bit of research I found out that I actually have made changes to both master
(the branch I was supposed to work on) and to my detached HEAD state. So, when I tried to merge them (following the answers below) some conflicts occurred. Since, I am content with my current state (besides being a detached HEAD) I reverted the merge with:
git reset --hard HEAD
and just kept my code in a new branch. Since, there is no risk of data loss this solution satisfies me.