【My Study Note】HEAD
HEAD
The hidden folder called “.git” is located in each project. This folder is responsible for keeping track of all changes across the project.
How does it know what branch you’re currently on?
It keeps a special pointer called head which is one of the files inside the dot git folder. This file refers to the current committee you are viewing.
How to identify the current committee you are working on
1. Open the .git folder on your terminal and type:
cd .git
2. Type cat HEAD and press enter
cat HEAD
In git, we only work on a single branch at a time.
How git head works
So I am here in the terminal, to see what branch I am in, I am running get branch. And I can see I’m on the main branch.
git branch
feature/testing-branches
* main
To confirm that you are in the main branch, I run the cat dotgit forward slash head command and press enter.
cat .git/HEAD
ref: refs/heads/main
That brings me back to the reference to where it actually points to. In this case, you can see the references pointing to the heads main.
If I change my branch to feature testing branches, I use the git checkout command.
git checkout feature testing/branches
I then go to my head file inside the git folder by typing cat dot get forward slash head. The ref is now pointing to the feature testing branches.
cat .git/HEAD
ref: refs/heads/feature/testing-branches
I’ll go back into my main branch by typing git checkout main.
// Going Back to the main branch
git checkout main
Then, check the reference file inside the main directory using the cat command again. When I press enter, I get a hash ID. This is a reference to the latest commits of that working directory.
cat .git/refs/heads/main
8b5592b5198248c4.........