Command Reference

git-update-ref Tutorial

Explains how to use git-update-ref to update refs through a lower-level interface.

Who This Is For
  • Developers who already know basic commit and branch actions
  • Readers who want to understand command boundaries and risk
Prerequisites
  • A basic mental model of worktree, index, and commits
  • Comfort reading `git status` and a small commit graph
Common Risks
  • Using local cleanup commands on already shared history
  • Continuing to rewrite before confirming a recovery path

The short version

git-update-ref is used to update refs through a lower-level interface.

When it is a good fit

  • when you need to update refs through a lower-level interface
  • when you want this step to be repeatable instead of ad hoc
  • when you need a clearer mental model of what Git is recording or updating

Basic example

git update-ref refs/heads/feature HEAD

What to watch most closely

Plumbing commands are closer to Git internals, so check whether a safer high-level command already solves the problem.

A safer working habit

Treat it as a read-only inspection tool first, then move to write-oriented usage only when necessary.

Useful angles for understanding it

  • Inspect lower-level objects and refs
  • Write scripts or debug advanced issues
  • Verify internal repository state

Related reading

Read it alongside git status, git log, and git show so it is easier to see how the command changes history, refs, the index, or the working tree.

What problem this command solves in a workflow

git update-ref solves the problem of "updating references at a low level (creating, moving, or deleting branches and tags)". It bypasses high-level commands like git branch and git tag, directly manipulating reference files, and supports atomic old-value validation.

Typical use cases

  • Create or move a branch in a script by running git update-ref refs/heads/feature HEAD to point the feature branch at the current commit.
  • Atomically update a reference and prevent concurrent conflicts by using git update-ref refs/heads/branch NEW_HASH OLD_HASH — the update only proceeds if the old value matches.
  • Delete a reference with git update-ref -d refs/heads/old-branch to directly remove a branch reference.

Diagram view

Update references at a low levelupdate-ref writes directly to reference files (.git/refs or packed-refs), creating, modifying, or deleting references. It is a write operation with support for atomic old-value validation.
Reference operation
Reference path (e.g. refs/heads/main)Target commit hashOld-value check (optional)
Results
Updated referenceNewly created branch/tagDeleted reference
update-ref is a low-level command that writes directly to references. It bypasses safety checks of high-level commands — confirm the reference name and target hash before using.

Special cases and boundaries

  • git update-ref is a write operation that directly modifies where a reference points. Creating or moving branches, tags, and other references changes repository state.
  • Using old-value validation (the third parameter) enables atomic conditional updates: the reference is only updated if its current value matches the expected old value, preventing silent overwrites in concurrent scenarios.
  • Writing references directly bypasses the validation and protection of high-level commands like git branch and git tag — a typo in the reference name could accidentally create an unwanted branch.
  • update-ref does not check whether the target hash points to a valid commit object — even if the hash does not exist, the reference will be created.
  • When using -d to delete a reference, an error is thrown if the reference does not exist; adding -no-deref deletes the symbolic reference itself rather than the target it points to.