Refs
- Git course
- Expert
- Lesson 3/32
- 4 min
Learn branch and tag references.
What Are Git Refs?
Refs are named references used to access Git objects. A branch reference usually points to the latest commit on that branch. Instead of memorizing long hash values, you can use meaningful names such as main or feature.
.git/refs/
├── heads/
└── tags/Refs allow Git to track specific points in commit history by name.
Heads and Tags References
refs/heads represents local branches, while refs/tags represents tags. A branch reference can move forward when a new commit is created. Tags are generally used to identify a specific commit, such as a release or an important point in history.
.git/refs/
├── heads/
│ └── main
└── tags/
└── v1.0These two reference types allow commit history to be named for different purposes.
Practice List Local Branch References
Display local branches and the references representing them. Restrict the for-each-ref command to the refs/heads namespace.
Starter code
# Yerel dal referanslarını listeleExpected output
refs/heads/main refs/heads/feature
Questions and answers
Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.
1 In which directory under .git/refs are local branch references stored?
- objects
- hooks
- heads Correct answer
- tags
Explanation: <code>refs/heads</code> contains references for local branches.
2 The Directory for Tag References
.git/refs/
├── heads/
└── tags/____
.git/refs/
├── heads/
└── tags/tags
Explanation: <code>refs/tags</code> stores Git tag references.
3 Reference Types and Locations
| Term | Meaning |
|---|---|
refs/heads |
Local branch references |
refs/tags |
Tag references |
main |
A branch name |
v1.0 |
An example of a version tag |