0

I would like to reset the local master branch to the commit that origin/master points at. This operation should make a reflog entry so that it can be reverted if need be. It is a requirement that this operation doesn't change the index, working tree, and that it can be performed regardless of the current HEAD, without moving HEAD or checking out any specific commit.

In other words, what is a safe git CLI equivalent of git rev-parse origin/master > .git/refs/heads/master?

Considered options:

  • git branch -f master origin/master
    • Not acceptable because it doesn't leave a record in the reflog
Grant Zvolsky
  • 483
  • 5
  • 6

2 Answers2

2

Use git update-ref:

git update-ref -m 'reset' refs/heads/master origin/master
FelipeC
  • 9,123
  • 4
  • 44
  • 38
1

The command

git branch -f master origin/master

resets branch master to origin/master, and it does create a reflog entry. The entry can be viewed using one of the following commands:

git reflog show --all
git reflog show master --
Grant Zvolsky
  • 483
  • 5
  • 6