I want to build into my deployment the ability to checkout the users branch and the commit id he is using.
In the past we only checkout out of master on our deployment boxes. I did this and it seemed to work.
git checkout HASH
But now I want the ability to test a branch and hash on our staging boxes. How do I do that? I thought if I reset to a HASH it would infer the branch but that didn’t work. I thought I could just do a checkout branch HASH.
How can I recreate the users current checkin on his branch on our staging server?
A commit hash by itself does not refer to a branch; it refers to a commit which may be present on multiple branches, or even none at all.
A branch is just a name that points to a commit hash (and this pointer moves as commits are added to the branch).
To check out a branch, you need to use
git checkout <branch>.If you are pushing just a hash, you need to switch to pushing a branch by name for the branch name to be known on your staging boxes.
You don’t need to check out a branch if this is all you need. Just use
git checkout HASHas you are already doing. This is guaranteed to always reflect the same thing.