swf.wtf
Feb 21, 2026 guide git linux beginner

Git from Zero.
// no fluff, just commits.

Everything you actually need to start using Git — from install to your first push.

$ git status
On branch main
Your branch is up to date with 'origin/main'.
nothing to commit, working tree clean
$ git log --oneline -3
4a2f1bc feat: add dark mode toggle
9e0d3aa fix: correct typo in README
1c8b77e init: first commit
$ _
// contents
What is Git? Install & configure Core concepts The daily workflow Branches Working with remotes Cheat sheet

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.

// key distinction
Git is the version control tool. GitHub / GitLab / Codeberg are websites that host Git repositories online. Git works perfectly fine without any of them — but they make collaboration easy.

Install & configure

Install Git

pop!_os / ubuntu / debian
sudo apt install git -y
fedora
sudo dnf install git -y
arch
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.

bash
# 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)

bash
# 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

bash
# 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.

repository (repo)
A folder tracked by Git. Contains your files + the entire history of every change ever made.
commit
A snapshot of your files at a point in time. Like a save point. Has a unique ID and a message.
staging area
A holding zone. You add files here before committing. Lets you choose exactly what goes into a commit.
branch
A parallel version of your code. Work on features in isolation without breaking the main codebase.
remote
A copy of your repo on another machine or server (like GitHub). Push your commits there to share them.
HEAD
A pointer to your current location. Usually points to the latest commit on your current branch.

The daily workflow

This is the loop you'll repeat a thousand times. Burn it into your muscle memory.

1 edit files
2 git add
3 git commit
4 git push

Start a new repo

bash
# 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

bash
# 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

bash
# 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

bash
# 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"
// good commit messages
Write commit messages in the imperative: "add feature" not "added feature". Keep it under 72 characters. A common prefix convention: 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.

bash
# 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
// merge conflicts
When two branches change the same lines, Git can't decide which to keep — that's a conflict. Git will mark the conflicting sections in your file with <<<<<<< / ======= / >>>>>>>. 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.

bash
# 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
// use SSH, not HTTPS
Set up an SSH key so you never have to type your password. Generate one with ssh-keygen -t ed25519 -C "you@example.com", add it to GitHub, and use the SSH clone URL. Way smoother.

Cheat sheet

// the commands you actually use
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
Create a .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.