What is Git?
The short answer: Git is a version control system for tracking changes over time.
The longer answer: Git (created by Linus Torvalds) is a tool for versioning essentially any kind of data, though it’s most commonly used for source code. It scales from solo projects to massive open-source efforts (Git was originally built to support the Linux kernel).
Under the hood, Git stores history as a graph of commits and uses checksums (historically SHA‑1) to efficiently identify and validate content. If you want a deeper mental model, the “four objects” explanation is excellent: blob, tree, commit, tag.
Getting set up (once)
Before you start:
- Create an account on a host like GitHub.
- Install Git: Installing Git
- Configure it: First-time Git setup
If you’ll be pushing/pulling frequently, it’s worth setting up SSH keys:
- Git book: Generating your SSH public key
- GitHub: Generating SSH keys
- Bitbucket: Set up SSH for Git
Optional but nice: configure a merge/diff tool. (Example: Kaleidoscope on macOS.)
Helpful resources
- Pro Git (free book): Pro Git
- Mental model: Think like a Git
- Cheat sheet (PDF): Git Cheat Sheet
- Tips & tricks (older, still useful): Git tricks, tips & workflows
- GUI client: Tower
- More tools: Git GUI downloads
Core commands (the ones you actually use)
Clone
Copy a repository to your machine:
git clone [email protected]:git/git.git
That creates a working directory plus a hidden .git/ folder containing the full history.
Add
Stage changes (choose what will go into the next commit):
git add .
Commit
Create a snapshot of the staged changes:
git commit -m "Explain what changed and why"
Commit early and often. Small, focused commits are easier to review and revert.
Pull (fetch + integrate)
Update your current branch with changes from the remote.
- The common “just do the thing” command:
git pull
- If you want to be explicit about remote and branch (example uses
main):
git pull origin main
Under the hood, git pull is basically git fetch followed by an integration step (merge by default; rebase if you configure it that way).
Push
Send your local commits to the remote:
git push
If you just created a new local branch, publish it and set upstream tracking:
git push -u origin my-branch-name
Branching, stashing, merging, rebasing
Stash
Temporarily set aside uncommitted work:
git stash
Bring it back (and remove it from the stash list):
git stash pop
Apply without removing (safer if you’re juggling multiple stashes):
git stash apply
Rebase (use with care)
Rebase is useful when you want a cleaner, more linear history by replaying commits on top of a new base.
Learn more: Atlassian: git rebase
Two common patterns:
git rebase main
and interactive rebase (rewrite the last 2 commits):
git rebase -i HEAD~2
Interactive rebasing lets you squash/reword commits. It’s powerful—also easy to misuse. Avoid rebasing commits that you’ve already pushed and that others might have based work on.
Merge
Merge combines one branch into another:
Learn more: Atlassian: git merge
Example:
git checkout main
git merge feature/xx
