Hello, I'm Ganesh. I'm working on FreeDevTools online, currently building a single platform for all development tools, cheat codes, and TL; DRs — a free, open-source hub where developers can quickly find and use tools without the hassle of searching the internet.
In this blog, we will understand how Git knows in which commit we are working and the structure of git.
Head: Pointer for git Commit
Git uses the head for tracking location. It is Pointer instead of pointing for the commit; it points at a branch.
Let's assume we are in the main branch.
The head will be pointing to the branch name, and the branch will be pointing to the commit.
Commit will be your current location.
If we want to create a branch "feature"
git checkout feature
Suppose we want to check a specific commit. We will use git to point to the specific commit. This will be known as detached HEAD. There will be no branch pointing between head and commit.
Actually, we can commit a few more changes. But when we switch to a different commit, it will be orphaned, and no branch will be pointing to it; this will be known as an orphaned commit.
Git garbage collection will clean it within 30 - 60 days.
Actual Reality: We usually try to see in old commits in detached mode. We fix and commit changes. When we move back to the main branch, all commits will be lost.
That is why git warns that the head is in detached mode.
Structure of Git.
Git will have 3 stages.
- Working Directory
This consists of actual files.
- Staging Directory
Will be having a change file copy.
uses: git add .
- Repository
Database of commits, also called permanent history.
uses: git commit -m "update"
Conclution
We understood how Git points to the commit we are working on and the structure of git.
In the next blog, we will learn about git checkout, git reset, and git revert.
I’ve been building for FreeDevTools.
A collection of UI/UX-focused tools crafted to simplify workflows, save time, and reduce friction when searching for tools and materials.
Any feedback or contributions are welcome!
It’s online, open-source, and ready for anyone to use.
👉 Check it out: FreeDevTools
⭐ Star it on GitHub: freedevtools

Top comments (0)