

If you use the git log –oneline command, you’ll see something like this: Then we created a new empty file and committed that with the message “Create file.” Next, we added a line to that file and committed the change, with the message “Add a line to the file.” Finally, we’ve created another file with one line of text and committed that as well. With the commands above, we’ve created a new folder with a new repository inside it. git commit -m "Create file" echo "Hello World!" > file.txt git commit -a -m "Add line to the file" echo "Second file" > file2.txt git add. Mkdir git-head-demo cd git-head-demo git init touch file.txt git add. We’ll create a repository and add some commits to it:
#Rebase head to smartgit how to
Let’s start with a quick demo showing how to reach the detached HEAD state. Git Detached HEAD: Reproducing the “Problem” By the end of it, you’ll have a better understanding of Git’s fundamentals, and detached HEADs will never trouble you again. What does HEAD mean in Git? What does it mean for it to be attached or detached? These are the kind of questions we’ll answer in this post. If you just want to do that and get on with your day, go to the “How Do I Fix a Detached Head in Git?” section of this post to see how it’s done.īut if you want to know more-and I guess you do-stick around and we’ll help you. The second thing you need to know is that going back to normal is super easy. Sure, it’s not the normal state, which would be-you’ve guessed it!-when HEAD is attached. The expression “Detached HEAD” might sound somewhat bizarre, but it’s a perfectly valid repository state in Git. Your repo isn’t broken or anything like that. Here’s the first thing you should know: you haven’t done anything wrong. If that’s your case, you’ve come to the right place. After coming across this message, most people start furiously Googling “git detached HEAD,” “git detached HEAD fix,” or similar terms, looking for anything that might be of help. The “You are in ‘detached HEAD’ state” one is certainly one of the weirdest. Newcomers to Git often get confused with some of the messages that the VCS tool throws at them.

The following is a guest blog post written by Carlos Schults. "Git detached head" is a weird error message to receive.
