Home > Enterprise >  How to safely perform `git rev-parse origin/master > .git/refs/heads/master`
How to safely perform `git rev-parse origin/master > .git/refs/heads/master`

Time:09-02

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

CodePudding user response:

Use git update-ref:

git update-ref -m 'reset' refs/heads/master origin/master

CodePudding user response:

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 --
  •  Tags:  
  • git
  • Related