~/blog git-concepts-that-confuse-beginners
Git Concepts That Confuse Beginners
Git Concepts That Confuse Beginners
Git is powerful, but some ideas are hard at first. Here are the concepts that confused me, explained simply.
The Three Areas
Git has three main areas:
- the working directory: your files right now
- the index (staging area): files you added with
git add - the repository: the committed history
Understanding these three makes most Git commands easy.
Branches Are Just Pointers
A branch is not a copy of your code. It is just a pointer to a commit. When you commit, the pointer moves forward.
This is why creating branches is so cheap and fast.
HEAD Is Where You Are
HEAD is a pointer to your current position. It usually points to a branch. When you move between commits, HEAD moves with you.
Merge vs Rebase
Both join work from different branches, but in different ways:
- merge creates a new commit that combines histories
- rebase moves your commits on top of another branch for a cleaner history
As a beginner, merge is easier to understand. Use rebase when you want a cleaner line of commits.
What "Detached HEAD" Means
If you check out an old commit directly, you get a detached HEAD. You are not on any branch. New commits here can be lost easily.
To be safe: create a new branch before making changes.
How to Practice
The best way to learn Git is to use it:
- create a test repository
- try commit, branch, merge, and rebase
- break things on purpose and fix them
Final Thoughts
Git feels confusing because it is different from normal file work. Once you learn the three areas and pointers, the rest becomes clear.