Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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

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:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

  • git branch -f master origin/master
    • Not acceptable because it doesn’t leave a record in the reflog

>Solution :

Use git update-ref:

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

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading