Introduction to Git
Git is a distributed version control system (DVCS) created by Linus Torvalds in 2005 to manage Linux kernel development. Today it is the industry standard — virtually every software team uses Git to track code changes, collaborate, and deploy software.
Why Version Control?
Without version control:
- “Final_v2_REAL_final.js” file naming chaos
- No history of who changed what and why
- Fear of breaking working code — no easy rollback
- Painful collaboration — emailing zip files
With Git:
- Complete history of every change
- Branch to experiment without affecting main code
- Merge work from multiple developers
- Revert to any previous state in seconds
Centralized vs Distributed
| Model | Examples | Weakness |
|---|---|---|
| Centralized | SVN, CVS | Single server failure blocks all work |
| Distributed | Git, Mercurial | Every clone is a full backup |
In Git, every developer has the entire repository history locally. You commit offline, push when ready.
Core Concepts
Working Directory → Staging Area → Local Repository → Remote Repository
(your files) (git add) (git commit) (git push)
| Term | Meaning |
|---|---|
| Repository (repo) | Project folder tracked by Git |
| Commit | Snapshot of files at a point in time |
| Branch | Independent line of development |
| Merge | Combine changes from branches |
| Remote | Shared repository (GitHub, GitLab, Bitbucket) |
| Clone | Copy a remote repo locally |
How Git Tracks Changes
Git stores content as snapshots, not diffs. Each commit references a tree of files with SHA-1 hashes:
commit a1b2c3d (HEAD -> main)
Author: Alice <[email protected]>
Date: Thu Jun 13 2024
Add user authentication
commit e4f5g6h
Initial project setup
Every commit is immutable — changing history creates new commit hashes.
Your First Repository
mkdir my-project && cd my-project
git init
echo "# My Project" > README.md
git add README.md
git commit -m "Initial commit"
View history:
git log --oneline
# a1b2c3d (HEAD -> main) Initial commit
Git vs Other Tools
Git vs SVN: SVN uses a single central server; commits go directly to it. Git commits locally first — faster, works offline, flexible branching.
Git vs GitHub: Git is the tool; GitHub/GitLab/Bitbucket are hosting platforms. You can use Git entirely offline without any remote.
Git vs Dropbox/Google Drive: Cloud drives sync files but don’t understand code history, merges, or branches. Never use file sync for source code.
Typical Team Workflow
main (production-ready)
↑ merge PR
feature/login (Alice's branch)
feature/dashboard (Bob's branch)
- Pull latest
main - Create feature branch:
git checkout -b feature/login - Commit changes locally
- Push branch and open Pull Request
- Code review, CI tests pass
- Merge to
main - Deploy
Git Configuration
Set identity once globally:
git config --global user.name "Simon Sheng"
git config --global user.email "[email protected]"
git config --global init.defaultBranch main
git config --global core.editor "code --wait"
Useful defaults:
git config --global pull.rebase false # merge on pull (default)
git config --global color.ui auto
git config --global alias.st status
git config --global alias.co checkout
git config --global alias.br branch
git config --global alias.lg "log --oneline --graph --all"
Common Git Hosting Platforms
| Platform | Notes |
|---|---|
| GitHub | Largest open-source community, Actions CI/CD |
| GitLab | Self-hosted option, built-in CI/CD |
| Bitbucket | Atlassian integration (Jira, Confluence) |
| Azure DevOps | Microsoft ecosystem |
What Comes Next
Continue to Git Basics for daily commands, then branching, advanced techniques, and team collaboration. Git proficiency is non-negotiable for any developer role.