3

I use git to build my website. In my local WAMP environment I add my final changes, adds, commits and push them to Github:

git add .
git commit -m "my message"
git push origin my_dev_branch

Then (still locally) I create a production tag with:

git tag prod_20160816

... and push it to the remote Github repo too.

git push prod_20160816

After that I login on my remote server with Putty and run:

git pull
git checkout prod_20160816
git status

Now to my question. After that last row I get the message "Not currently on any branch" (among other info). Is this what is called a detached HEAD state? And most important... is it normal to use this state on the production site?

1 Answer 1

2

You are detached because you checked-out a tag, not a branch.

IMO, there is nothing wrong in doing so, as detached is only a problem when you commit (the new commit will have no name and might get lost), but you won't probably commit from your production server.

Anyway, what I do in my projects is to create a branch and a tag to the same commit, but then push the branch instead of the tag. The tag is used only for debugging reference, history, rolling back... but the release version is always the head of the branch.

4
  • Thanks for your answer. Since I haven't used the master branch during development, I suppose I could use that as a "production branch" and create a tag to that commit? May I ask how your git commands would look like, supposing I am on a branch called dev?
    – TBJ
    Commented Aug 17, 2016 at 7:37
  • @TBJ: Sure. Imagine that HEAD is the commit I want to release as a new version. Then I do git branch ver.major HEAD and git tag ver.major.0 ver.major, and push the branch or the tag (they are the same). If then I need to patch that release I will do git checkout ver.major fix whatever is needed (cherry-pick from master usually), git add/commit and git tag ver.major.1 ver.major. Then push the branch or the new tag.
    – rodrigo
    Commented Aug 17, 2016 at 7:44
  • So you think it's better to create a new release branch + tag, and not merge HEAD into the master branch + tag? I haven't used the master branch, so I thought that would be a possibility. I learn as I go, thanks a lot for sharing.
    – TBJ
    Commented Aug 17, 2016 at 7:57
  • @TBJ: You're welcome! And that depends on your release model. If you only have one production machine, then supporting older releases is quite useless, because nobody will use them. But if you have a big base installation, with different version each, then support branches are quite handy.
    – rodrigo
    Commented Aug 17, 2016 at 8:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.