Git - Refs


A ref (or reference) is a human-readable name given to a commit SHA-1 hash.

When referring to a Git commit, you can refer it by name with a reference

A Git reference can be rewritten to point to a new commit.

Refs are:

  • branches (A ref that stores the new Git commit hash.)
  • and/or tags

There is also symbolic refs (alias ref) point to a ref instead of directly pointing to a commit, the most common being HEAD

Ref to a SHA commit

All SHA commit are in file located under the directory git dir/refs

Example for a head

cat .git/refs/heads/main

Remote Heads Refs

remote head refs

git ls-remote --heads remote

# default
git ls-remote --heads origin
dd39a644a4a7ec3e65135baaf48acd5f7f628510        refs/heads/master
6ead0945771dfd789aa97442ff10872f9665598d        refs/heads/stable
e245797039fa7b86c3a3fb32b45cfb998d8c76cd        refs/heads/v1.13

Git Repo

Physically, it's is a file under the refs directory in the repository directory that contains the commit hash.

Pull request

For Pull request such as Github Pull request, the ref value would be refs/pull/421/merge.

Discover More
Git Commit Tree Data Model
Git - Commit

A commit in git is an object that stores the information : who saved the file system snapshots, when they were saved, why they were saved. the commiter the author the parent commit It's...
Git - Current / working / HEAD / active branch

The current or active branch is: the branch checked out actually in the working tree The current branch is also known as the HEAD branch (in uppercase) that represents the last commit known...
Git - Detached HEAD

What means a DETACHED HEAD in git
Git - Local branch

A local branch is a branch that exists only on your computer. tracking branch There are two types of local branches: non-tracking local branches. They are not associated with any other branch....
Git - Objects (Database)

An object is the value in the entry of the git database key-value. All entities in git are objects. Objects are the entity of the Git file system. On the operating file system, the objects are stored...
Git - Remote reference

Remote references are references (pointers name) located in your remote repositories. ie remote branches, remote tags, and so on. You can get a full list of remote references explicitly...
Commit History Master
Git - Remote-tracking branch

Remote-tracking branches are local references to the state of remote branches You can't modify them. They’re just local references that you can’t move. They represent the state of the remote repository...
Git - Tracking Branch

Tracking branches are local branches that have set their upstream branch. tracking branchreference The local branches have then a direct relationship with their upstream branch that can be: a remote...
The .git repository

The .git metadata repository
Branches Git
Git - Branch

This page talks Branch management in Git. For Git, a branch is: a commit name (ref) that points to the last commit (head) leaf in the commit log (or log) that represents a commit chain Example...

Share this page:
Follow us:
Task Runner