1

I've added a deploy script which detects the current branch and then among other things run this:

currentBranch=$(git rev-parse --abbrev-ref HEAD)

eval "git fetch --all # fetch all remote branches"
eval "git reset --hard origin/$currentBranch" # clean up currentBranch

and if a new branch was supplied in the bash script I'll run this:

newBranch=$1
eval "git checkout $newBranch"

But, before I ran it I noticed the server's current branch is HEAD (should have been master).

What is the effect of git reset --hard origin/HEAD before I run the deploy. I don't care about any tracked files on HEAD I just want the switch to a new branch to test it, and later I'll return it to what it should be which is master. Just not sure what happens if I run the reset right now with a detached HEAD.

mtpultz
  • 17,267
  • 22
  • 122
  • 201
  • 2
    A side note: you don't need `eval` here - remove it and keep double quotes only around `$variables`. – Roman Sep 20 '15 at 22:09

1 Answers1

1

Based on this : HEAD should point to your local copy of the master, so resetting it (assuming that you are working on your branches and not on your master) should not cause you any problems.

Community
  • 1
  • 1
Rann Lifshitz
  • 4,040
  • 4
  • 22
  • 42
  • I just want to emphasize that resetting the HEAD when it points to the master should only be done if no changes were made to the master, otherwise they will be lost. A good practice here might be to add a 'git branch [some other branch]' at the beginning of the script in order to make sure that the master is not accidentally effected. – Rann Lifshitz Sep 21 '15 at 16:29