Git Guide¶
Introduction¶
Git is a tool that helps you keep track of your code like a writer keeps track of drafts you never lose work, and you can always go back to a specific version of your story. Git isn’t just version control it’s time travel for your code. Good Git habits mean smoother teamwork, less stress, and better projects.
This guide will walk you through the essentials: installing Git, setting up your identity, working with commits and branches, and understanding the deeper concepts that make Git powerful.
Installing Git¶
You can’t version your code if you don’t have the tool. Simple as that.
Installing Git is like setting up your notebook before you start writing.
Configuring Git¶
A commit without an author is like a book with no writer. Always sign your work.
Core Commands¶
1. Clone a Repo¶
It’s like photocopying a notebook so you can start writing in your own copy.
2. Stage + Commit¶
Think of commits as journal entries each one should tell a clear part of the story.
3. Branching¶
Branches are alternate storylines. You can experiment without ruining the main plot.
4. Push + Pull¶
Collaboration is like dancing. Push your moves, pull your partner’s stay in sync.
Advanced Git Concepts¶
1. Detached HEAD¶
- You are viewing a specific commit instead of a branch.
- Any new commits here can be lost if you switch branches.
2. Rebasing¶
- Moves your branch commits on top of another branch.
- Keeps history linear but can change commit hashes.
3. Merge Conflicts¶
- Happens when changes in two branches conflict.
- You need to manually fix and commit.
4. Stashing¶
- Temporarily saves uncommitted changes.
- Useful when you need to switch branches without committing.
5. Cherry-picking¶
- Apply a specific commit from one branch onto another.
- Useful for copying small changes without merging whole branches.
6. Force Push¶
- Overwrites the remote branch with your local branch.
- Be careful — it can erase others’ work.
7. Reflog¶
- Tracks all movements of HEAD and branch tips.
- Lets you recover “lost” commits.
Confusing Concepts¶
1. Forking vs Cloning¶
- Forking → Make your own copy of someone else’s repository on GitHub.
- Cloning → Copy a repository (your fork or original) to your local computer.
- Key: Fork = online copy; Clone = local copy.
2. Tracking vs Staging¶
- Tracked files → Git already knows about them.
- Untracked files → Git doesn’t know about them yet.
- Staging (
git add
) → Preparing tracked/untracked files for the next commit.
3. Remote vs Local Branch¶
- Local branch → Exists only on your computer.
- Remote branch → Exists on GitHub (or another remote).
git push
→ Send your local branch to the remote.git pull
→ Update your local branch with remote changes.
4. HEAD¶
- HEAD → Points to the current commit or branch you’re on.
- Detached HEAD → HEAD points to a commit instead of a branch (commits can be lost).
5. Tags¶
- Tags → Mark a specific commit as important (e.g., v1.0 release).
6. Remote Tracking¶
- Tracking branch → Local branch linked to a remote branch.
- Helps Git know where to pull/push updates automatically.
7. Pull Requests (PRs)¶
- PR → Propose changes from one branch/fork to be merged into another branch.
- Mostly used for team collaboration on GitHub.
Best Practices¶
- Write meaningful commit messages → they’re letters to your future self.
- Don’t push broken code → respect the main branch.
- Pull before you push → avoid merge conflicts like awkward silences.
Closing Note¶
Git is more than commands , it’s a discipline of documenting your project’s history.
Every git commit
is a footprint of progress. Walk carefully.