Borek Bernard
Borek Bernard

Reputation: 53251

How to "reset" master to follow HEAD again after `git symbolic-ref`

At some point in the past, I've set master to follow my other branch, like this:

git symbolic-ref refs/heads/master refs/heads/my-other-branch

I want to go back to the state where master just tracks HEAD as usual. Can I just paste the most recent SHA1 into .git/refs/heads/master?

Upvotes: 1

Views: 56

Answers (1)

torek
torek

Reputation: 488193

You can, but the "officially correct" way is to use git update-ref with --no-deref to rewrite refs/heads/master without following the symbolic indirection that's currently in refs/heads/master.

In other words, if $sha1 is the correct SHA-1, both:

echo $sha1 > .git/refs/heads/master

and:

git update-ref --no-deref refs/heads/master $sha1

should work, but the latter is the "right" method, which should continue to work even if git evolves in the future such that the echo stops working. You can add a -m <reason> to the latter to add the <reason> string to the reflog as well (the direct echo method does not update the reflog, while update-ref does).

Upvotes: 3

Related Questions