til

git update-ref

git update-ref is a command that updates the value of a reference in the repository.

πŸ’‘ This is a low-level command that directly manipulates refs without creating reflog entries or performing safety checks. It’s useful for scripting or creating custom references.

Creating named references

git update-ref refs/heads/current HEAD

This command updates the refs/heads/current reference to point to the current HEAD.

git update-ref refs/heads/previous HEAD~1

This command updates the refs/heads/previous reference to point to the previous commit.

The ref name can be used in a git checkout command to switch to that commit.

git checkout previous

Deleting references

git update-ref -d refs/heads/previous

πŸ’‘ Use the -d flag to delete a reference safely.

Why use this?

πŸŽ‰ Happy coding!