Introduction
Git is the foundation of modern software development. Every GitHub repository, every pull request, every CI/CD pipeline runs on Git. Created by Linus Torvalds in 2005 to manage Linux kernel development, Git introduced distributed version control — where every developer has a complete copy of the repository with full history.
With over 60,000 GitHub stars on its mirror, Git is installed on virtually every developer machine in the world. GitHub, GitLab, Bitbucket, and Azure DevOps are all built on Git. Understanding Git is the most fundamental skill in software engineering.
What Git Does
Git tracks changes to files over time. It records snapshots (commits) of your project, lets you create parallel lines of development (branches), merge changes together, and collaborate with others. Every operation is fast because the complete history lives locally — no network access needed for commits, diffs, or logs.
Architecture Overview
[Working Directory]
Your actual files
|
git add
|
[Staging Area (Index)]
Changes ready to commit
|
git commit
|
[Local Repository (.git/)]
Complete history of all commits
Branches, tags, refs
|
git push / git pull
|
[Remote Repository]
GitHub, GitLab, Bitbucket
Shared with team
[Object Model]
blob -> file content
tree -> directory listing
commit -> snapshot + metadata
tag -> named referenceSelf-Hosting & Configuration
# Essential Git workflows
# Feature branch workflow
git checkout -b feature/new-login
# ... make changes ...
git add -A && git commit -m "Add login form"
git push -u origin feature/new-login
# Create Pull Request on GitHub
# Rebase to keep history clean
git fetch origin
git rebase origin/main
# Interactive rebase to squash commits
git rebase -i HEAD~3
# Stash changes temporarily
git stash
git checkout other-branch
git checkout -
git stash pop
# Undo last commit (keep changes)
git reset --soft HEAD~1
# View history
git log --oneline --graph --all
# .gitconfig — useful aliases
# [alias]
# co = checkout
# br = branch
# st = status
# lg = log --oneline --graph --decorate --all
# unstage = reset HEAD --Key Features
- Distributed — every clone is a full repository with complete history
- Branching — lightweight branches for parallel development
- Merging — powerful merge strategies and conflict resolution
- Staging Area — review and select changes before committing
- Speed — all operations are local and fast (written in C)
- Data Integrity — SHA-1 checksums ensure data is never corrupted
- Hooks — pre-commit, pre-push, and other automation hooks
- Submodules — include other repositories as dependencies
Comparison with Similar Tools
| Feature | Git | Mercurial | SVN | Perforce | Fossil |
|---|---|---|---|---|---|
| Type | Distributed | Distributed | Centralized | Centralized | Distributed |
| Speed | Very Fast | Fast | Moderate | Fast | Fast |
| Branching | Lightweight | Lightweight | Heavy | Streams | Lightweight |
| Learning Curve | Moderate | Low | Low | High | Low |
| Large Files | Via Git LFS | Built-in | Good | Excellent | Built-in |
| Hosting | GitHub, GitLab | Bitbucket | SVN servers | Helix Core | Built-in web |
| Market Share | Dominant (95%+) | Declining | Legacy | Enterprise | Niche |
FAQ
Q: How do I undo a commit? A: "git reset --soft HEAD~1" undoes the commit but keeps changes staged. "git revert HEAD" creates a new commit that undoes the changes (safe for shared branches).
Q: What is the difference between merge and rebase? A: Merge creates a merge commit preserving branch history. Rebase replays your commits on top of the target branch for a linear history. Use rebase for feature branches, merge for main/release branches.
Q: How do I handle large files in Git? A: Use Git LFS (Large File Storage) for binary files, media assets, and datasets. It stores large files on a separate server and tracks pointers in Git.
Q: Git vs GitHub — what is the difference? A: Git is the version control tool (local). GitHub is a hosting platform for Git repositories with added features: pull requests, issues, actions, and collaboration tools. GitLab and Bitbucket are alternatives to GitHub.
Sources
- GitHub Mirror: https://github.com/git/git
- Documentation: https://git-scm.com/doc
- Pro Git Book: https://git-scm.com/book
- Created by Linus Torvalds (2005)
- License: GPL-2.0