Git Basics
AI Learning Mentor
Generative insights & diagnostic help
The Three Stages of Git
Unlike other systems, Git models code safety using three distinct workspaces. Understanding how files move between these areas is critical:
- Working Directory: The local directory where you actively add, edit, or delete files. Files here are either untracked or modified.
- Staging Area (Index): A buffer workspace where you prepare changes for the next checkpoint. Files are placed here using
git add. - Local Repository: The secured database inside the hidden
.git/directory. Committing files viagit commitseals them in history.
The Committing Lifecycle
A commit represents a complete snapshot of your repository's state at a specific point in time. It is cryptographically sealed with a unique SHA-1 hash:
# Typical commit lifecycle
$ git add index.html
$ git commit -m "feat: add responsive layout"
[main 7c3aed5] feat: add responsive layout
Always write descriptive commit messages that clearly explain the **why** behind your changes to help teammates follow repository timelines.
Branching Basics
Branches are simply lightweight, moveable pointers to commits. They allow multiple developers to work on features concurrently without affecting production code:
git branch [name]: Creates a new local pointer.git checkout [name]orgit switch [name]: Shifts focus to the target branch.git merge [name]: Integrates the commits from the target branch into your active branch.