LinuxCommandLibrary

git-symbolic-ref

Create, read, or delete symbolic ref names

TLDR

Store a reference by a name

$ git symbolic-ref refs/[name] [ref]
copy

Store a reference by name, including a message with a reason for the update
$ git symbolic-ref -m "[message]" refs/[name] refs/heads/[branch_name]
copy

Read a reference by name
$ git symbolic-ref refs/[name]
copy

Delete a reference by name
$ git symbolic-ref [[-d|--delete]] refs/[name]
copy

For scripting, hide errors with --quiet and use --short to simplify ("refs/heads/X" prints as "X")
$ git symbolic-ref [[-q|--quiet]] --short refs/[name]
copy

SYNOPSIS

git symbolic-ref [-q] HEAD
git symbolic-ref [-q] -d
git symbolic-ref [-q] -m HEAD
git symbolic-ref [-q] --short HEAD
git symbolic-ref [-q] --quiet
git symbolic-ref --delete

PARAMETERS

HEAD
    Reads the symbolic ref 'HEAD'.


    The name of the symbolic ref to manipulate (e.g., refs/heads/mybranch).

-d
    Deletes the symbolic ref.

--delete
    Deletes the symbolic ref.

-m
    Updates the reflog with the specified .

-q
    Quiet; suppress error messages.

--quiet
    Quiet; suppress error messages.

--short
    Output the ref with its name shortened.

DESCRIPTION

The git symbolic-ref command is a powerful tool for managing symbolic references in Git.
A symbolic ref is essentially a pointer to another ref (usually a branch). The most common symbolic ref is HEAD, which points to the currently checked-out branch. This command allows you to read, create, update, and delete these symbolic references.
It's useful for scripting and advanced Git workflows where you need to programmatically manipulate refs. Improper usage can lead to a corrupted repository, so proceed with caution. The primary use case is manipulating the HEAD ref, but it can handle other symbolic refs as well. The command can also perform a sanity check while updating or deleting.

CAVEATS

Modifying symbolic refs directly can be dangerous if not done carefully. Always double-check the ref name before making changes. If you delete HEAD without creating a new branch you can leave the repository in a detached HEAD state.

EXAMPLES

1. Set HEAD to point to a new branch:
git symbolic-ref HEAD refs/heads/newbranch

2. Delete a symbolic ref:
git symbolic-ref --delete refs/heads/symref

SEE ALSO

git checkout(1), git branch(1), git update-ref(1)

Copied to clipboard