I'm trying to write a git deployment script, but the script has to update several servers and they aren't all on the same Git branch. Ideally the script should need just one command, to the effect of "git reset --hard origin/whateverBranchThisServerIsOn".
Now, I understand that I can do:
git reset --hard origin/foo
to reset my git environment to the remote foo branch. However, what I'd like to do is reset to a remote branch, but not "foo" specifically, just "the remote of whatever branch the machine currently has checked out (ie. what branch shows up when you do git branch
".
I've tried:
git reset --hard origin
and:
git reset --hard origin/HEAD
and:
git reset --hard HEAD
but they all either checkout other branches, or (in the last case) don't get the remote commits. Surely there is some way to say git reset --hard origin/CURRENT_BRANCH
?
The idea of "the branch I have checked out" is a little malformed. There is no 1:1 relationship between branches like that. Your branch may not have an "origin" at all. But it can have a remote tracking branch, which may (or may not) have the same name as the one you are on. Reading man gitrevisions
, it looks specifying HEAD@{upstream}
should work to do what you want. But I haven't tested it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With