Using Refs And Reflogs In Git
Last Updated :
17 Nov, 2025
Refs(short for references) are pointers to specific commits in a Git repository. They serve as labels for specific points in your project's history. Common refs include branches, tags, and the HEAD.
Types of Refs
- Branches: A branch is a movable pointer to the latest commit in development. When you create a new branch, Git creates a new pointer that moves as you make new commits.
- Tags: Tags are static pointers, often used to mark release point. Unlike branches, tags do not move.
- HEAD: A special ref that points to the currently checked-out commit (usually a branch head).
Viewing Refs in a Git Repository
Refs are stored as a normal file text in .git/refs directory. To explore refs in one of the project's repositories navigate to .git/refs or type the following command in Git bash in the root directory of your project.
$ ls -F1 .git/refs
or type the command in Git bash in the root directory of your project
find .git/refs
You should see the following structure, but it will contain different files depending on what branches, tags and remotes you have in your repo.
$ ls -F1 .git/refs
├── heads/
│ └── master
├── remotes/
├── tags/

All local branches of the repository are defined in refs/heads/ directory. Each file name matches names of the corresponding branch, and inside the file, you will find a commit hash. This commit hash is the location of the tip of the branch.
What are Git Reflogs?
A reflog (reference log) records when the tips of branches and other refs were updated in your local repository. Every time you:
- switch branches,
- commit,
- stash,
- reset, or
- rebase,
Git logs the movement of that reference into the reflog.
For example, Head@{2} points to where HEAD was two updates ago.
$ git reflog HEAD@{2}
$ git reflog

This command manages information recorded in reflogs.
Common Git Reflog Commands
Git reflog commands come with various subcommands for advanced usage:
git reflog [show] [log-options] [<ref>]
git reflog expire [--expire=<time>] [--expire-unreachable=<time>]
[--rewrite] [--updateref] [--stale-fix]
[--dry-run | -n] [--verbose] [--all [--single-worktree] | <refs>…]
git reflog delete [--rewrite] [--updateref]
[--dry-run | -n] [--verbose] ref@{specifier}…
git reflog exists <ref>
Words in square brackets such as "show", "log-options" are qualifiers, or we can say arguments to git reflog command.
Whether you are fixing mistakes or just understanding what happened, mastering refs and reflogs can make you much more confident using Git.
- Git Reflog Show: The "show" subcommand (which is also default, in absence of any subcommand) shows logs of the reference provided in command(or HEAD, by default). The reflog covers all recent actions, and in addition HEAD reflog records branch switching.
- Git Reflog Expire: The "expire" subcommand prunes older reflog entries. Entries older than "expire" time, or entries older than "expire-unreachable" time and not reachable from the current tip, are removed from the reflog. This is typically not used directly by end users
- Git Reflog Delete: The "delete" subcommand deletes single entries from the reflog. Its argument must be an exact entry (e.g. "git reflog delete master@{2}"). This subcommand is also typically not used directly by end users.
- Git Reflog Exists: The "exists" subcommand checks whether a ref has a reflog. It exits with zero status if the reflog exists, and non-zero status if it does not.
-
Files containing staging information
-
Pointers that refer to specific commits in a repository
-
Temporary storage for deleted commits
-
Backup copies of working directory files
Explanation:
Refs act as pointers/labels to commits. Branches, tags, and HEAD are all references that track commit points in history.
Which ref represents the commit currently checked out in the working directory?
Explanation:
HEAD always points to the current commit, usually the latest commit of the checked-out branch.
What is the major difference between branches and tags?
-
Tags move with commits; branches stay constant
-
Branches move forward with commits; tags remain static
-
Tags point to files; branches point to commits
-
Explanation:
Branches are movable pointers, updating with new commits. Tags are fixed/immutable references, often marking release points.
What does git reflog track?
-
Only commits in remote repository
-
-
Movements/updates of refs such as commit, reset, checkout etc.
-
Explanation:
Reflog records changes in references like switching branches, committing, resetting — allowing recovery of past states.
Which reflog subcommand deletes a specific entry from reference logs?
Explanation:
git reflog delete ref@{number} deletes a specific reflog entry if required.
Quiz Completed Successfully
Your Score : 2/5
Accuracy : 0%
Login to View Explanation
1/5
1/5
< Previous
Next >
Explore
Git Introduction
Git Installation and Setup
All Git Commands
Most Used Git Commands
Git Branch
Git Merge
Git Tools and Integration
Git Remote Repositories
Collaborating with Git
Advanced Git Commands