Git
Last edited by dave on 01/12/2025, 08:10:33 UTC
Contents
Quick Snapshot
- Type: Distributed version control system.
- Created by: Linus Torvalds (yes, the same Linux guy).
- First released: 2005.
- Core idea: Track changes in code (or any text files) efficiently and collaboratively.
- License: GNU General Public License (GPLv2).
- Tagline (unofficial): “Because losing your code should never be an option.”
- Website: git-scm.com
A Brief History
In 2005, the Linux kernel team needed a better way to manage massive amounts of source code.
They had tried commercial systems like BitKeeper, but when that relationship soured, Linus Torvalds built Git — a fast, distributed, and reliable alternative.
It quickly became the de facto standard for version control, now powering everything from tiny open-source projects to enterprise monorepos.
Core Concepts
Repositories (Repos)
A repository is a Git project — your code, its history, and all related metadata.
It can live locally on your computer or remotely (like on GitHub, GitLab, or Bitbucket).
git init my-project cd my-project
Boom — you just made a repo.
Commits
A commit is a snapshot of your project at a specific point in time.
Each commit has:
- A unique hash (like
a1b2c3d4) - An author
- A timestamp
- A message describing what changed
git add . git commit -m "Fix broken penguin emoji rendering"
Branches
Branches let you experiment without breaking the main codebase.
You can think of them as alternate timelines.
git checkout -b feature/sandwich-ai
Work freely, then merge your changes back when ready.
Merging & Rebasing
- Merge: Combines two branches, preserving their histories.
- Rebase: Moves your changes on top of another branch, keeping history linear.
Merging feels like collaboration; rebasing feels like time travel. Both are useful.
git merge main # or git rebase main
The Staging Area
Git tracks changes in three zones:
- Working Directory: Where you edit files.
- Staging Area: Where you prepare commits.
- Repository: Where your history lives.
You can check what’s where:
git status
Remote Repositories
To collaborate, you’ll push and pull code to a remote server:
git remote add origin https://github.com/user/repo.git git push -u origin main
Remote services (like GitHub) also enable pull requests, issue tracking, and CI/CD integration.
Common Commands
If you are looking for the ultimate cheat sheet for Git, check out Git cheat sheet.
| Command | Description |
|---|---|
git init | Initialize a repository |
git clone <url> | Copy a remote repo locally |
git add <file> | Stage changes |
git commit -m "msg" | Save staged changes |
git status | See what changed |
git log | View history |
git diff | Compare changes |
git branch | List or create branches |
git checkout <branch> | Switch branches |
git merge <branch> | Merge a branch into current |
git pull | Fetch + merge remote updates |
git push | Upload local commits to remote |
The Distributed Magic
Unlike centralized systems, every Git clone is a complete copy of the repository, including history.
That means you can:
- Work offline.
- Recover everything, even if the main server disappears.
- Experiment freely without fear.
.gitignore
Not every file belongs in version control.
The .gitignore file tells Git what to leave out — things like build artifacts, logs, and node_modules.
Example:
node_modules/
dist/
.env
Collaboration Workflow
Typical flow:
- Clone the repo.
- Create a branch for your feature.
- Commit your changes.
- Push to remote.
- Open a Pull Request (PR) for review.
- Merge when approved.
Clean, traceable, and everyone stays (mostly) sane.
Advanced Tools & Concepts
- Tags: Mark specific commits, like releases.
git tag v1.0.0 - Stash: Temporarily save unfinished work.
git stash git stash pop - Cherry-pick: Apply a specific commit to another branch.
git cherry-pick <hash> - Hooks: Automate tasks on Git events (e.g., pre-commit linting).
- Submodules: Track other repos inside your repo (use carefully).
Git Internals (In Brief)
Git is really a key-value store of snapshots.
Commits point to trees (directories), which point to blobs (file contents).
Everything is identified by its SHA-1 hash, ensuring integrity and speed.
In essence, Git isn’t just version control — it’s a time machine for text.
Ecosystem
- GitHub — Social coding, PRs, issues, and collaboration.
- GitLab — DevOps integration, CI/CD pipelines.
- Bitbucket — Popular with enterprises and Atlassian users.
- Gitea / Gogs — Lightweight self-hosted alternatives.
All built on the same Git foundation.
Fun Facts
- Git’s name is British slang for “unpleasant person” — Linus’ own joke about himself.
- The
.gitdirectory is the brain of your repo; delete it, and history literally dies. - The Linux kernel is still managed with Git, by thousands of developers worldwide.
- You can store poems, notes, or recipes in Git. (Some people actually do.)
Backlinks (3)
- General
- User
- Redirects
No backlinks yet.
- Media
No backlinks yet.
- Categories
No backlinks yet.
Categories (0)
No categories assigned to this page.
Edit Level
> Signed In Users
Latest on Lounge
Join the conversation about the 'Git' article →
No comments yet. Be the first to comment!