Git from Zero.
// no fluff, just commits.
Everything you actually need to start using Git — from install to your first push.
What is Git?
Git is a version control system. It tracks changes to your files over time so you can see what changed, when it changed, who changed it, and roll anything back if you break something. Think of it as a time machine for your code.
It was created by Linus Torvalds in 2005 — the same person who started Linux — because he needed something fast and distributed to manage the Linux kernel. It stuck.
Install & configure
Install Git
sudo apt install git -y
sudo dnf install git -y
sudo pacman -S git
Set your identity
Before you make any commits, tell Git who you are. This gets embedded into every commit you make.
# Set globally (all repos on this machine) git config --global user.name "Your Name" git config --global user.email "you@example.com" # Set for just the current repo (overrides global) git config user.name "Your Name" git config user.email "you@example.com" # Verify everything git config --global --list
Set your default editor (optional but recommended)
# Use neovim (good choice) git config --global core.editor "nvim" # Or nano if you're not a masochist yet git config --global core.editor "nano"
Default branch name
# Use 'main' instead of 'master' git config --global init.defaultBranch main
Core concepts
You need to understand five things. Everything else is built on top of these.
The daily workflow
This is the loop you'll repeat a thousand times. Burn it into your muscle memory.
Start a new repo
# Create a new repo in the current folder git init # Or clone an existing one from GitHub git clone https://github.com/user/repo.git
Check what's going on
# See what's changed, staged, untracked git status # See a diff of unstaged changes git diff # See commit history git log --oneline
Stage your changes
# Stage a specific file git add filename.txt # Stage everything changed in the current directory git add . # Stage parts of a file interactively git add -p
Commit
# Commit with a message inline git commit -m "feat: add login form" # Stage all tracked files and commit in one step git commit -am "fix: correct typo in header"
feat: fix: docs: refactor: chore:
Branches
Branches let you work on things in isolation. Always branch off of main before starting new features. Merge back when done.
# List all branches git branch # Create a new branch and switch to it git switch -c feature/dark-mode # Switch to an existing branch git switch main # Merge a branch into current branch git merge feature/dark-mode # Delete a branch after merging git branch -d feature/dark-mode
<<<<<<< / ======= / >>>>>>>. Edit the file to keep what you want, then git add and git commit to finish the merge.
Working with remotes
A remote is just your repo on another server. origin is the conventional name for your primary remote.
# Add a remote (after creating a repo on GitHub) git remote add origin https://github.com/user/repo.git # See your remotes git remote -v # Push your commits to remote for the first time git push -u origin main # Subsequent pushes — just this git push # Pull latest changes from remote git pull # Fetch without merging (see what's changed) git fetch
ssh-keygen -t ed25519 -C "you@example.com", add it to GitHub, and use the SSH clone URL. Way smoother.
Cheat sheet
git init # start a new repo git clone <url> # copy a remote repo locally git status # see what's changed git add . # stage everything git add <file> # stage one file git commit -m "msg" # commit staged changes git push # push to remote git pull # pull from remote git log --oneline # pretty history git diff # see unstaged changes git switch -c <branch> # new branch + switch git switch <branch> # switch branch git merge <branch> # merge into current git stash # shelve changes temporarily git stash pop # bring them back git restore <file> # discard unstaged changes git reset --soft HEAD~1 # undo last commit, keep changes git config --global -l # list global config
.gitignore file in your repo root to tell Git what to ignore — node_modules/, .env, build artifacts, etc. GitHub has templates for most languages at github.com/github/gitignore.