Git for Dummies

Version control from scratch — Linux edition

Felipe A. Moreno-Vera

What you’ll learn

  • What Git is and why every developer uses it
  • How to install and configure Git on Linux
  • The core concepts: repos, commits, branches
  • The essential daily commands
  • How to work with GitHub / GitLab
  • How to fix the most common mistakes

Note

No prior experience needed. If you can open a terminal, you’re ready.

What is Git?

Git is a version control system — it tracks every change you make to your files over time.

Think of it like a save system in a video game, but for code:

  • You can go back to any previous save
  • Multiple people can play (work) simultaneously
  • You can try risky things in a separate slot without breaking the main game

Tip

Git ≠ GitHub. Git is the tool. GitHub is a website that hosts your Git repositories online.

Why bother?

Without Git

  • project_final.py
  • project_final_v2.py
  • project_FINAL_USE_THIS.py
  • project_FINAL_fixed.py
  • project_FINAL_fixed2_omg.py

With Git

  • project.py
  • Full history of every change
  • Who changed what and when
  • Easy to undo anything
  • Safe collaboration

1. Installing Git on Linux

Open a terminal and run the command for your distro:

Ubuntu / Debian / Mint

sudo apt update
sudo apt install git

Fedora / RHEL / CentOS

sudo dnf install git

Arch / Manjaro

sudo pacman -S git

Verify the installation:

git --version
# git version 2.x.x

2. First-time configuration

Before using Git, tell it who you are. This info is attached to every commit you make.

git config --global user.name "Your Name"
git config --global user.email "you@example.com"

Set your preferred text editor (for commit messages):

# Use VS Code
git config --global core.editor "code --wait"

# Use nano (simplest for beginners)
git config --global core.editor "nano"

# Use vim
git config --global core.editor "vim"

Check your config:

git config --list

3. Core concepts

Concept What it means
Repository (repo) A folder tracked by Git
Working directory Your files as you see them
Staging area Changes selected for the next commit
Commit A saved snapshot of your staged changes
Branch An independent line of development
Remote A copy of the repo hosted online (GitHub, etc.)

The three areas of Git

┌─────────────────────────────────────────────────────┐
│                  YOUR PROJECT                       │
│                                                     │
│  ┌─────────────┐  git add  ┌──────────────┐        │
│  │   Working   │ ────────► │   Staging    │        │
│  │  Directory  │           │    Area      │        │
│  └─────────────┘           └──────┬───────┘        │
│         ▲                         │ git commit     │
│         │                         ▼                │
│         │                  ┌──────────────┐        │
│         └──────────────────│  Repository  │        │
│           git checkout     │  (History)   │        │
│                            └──────────────┘        │
└─────────────────────────────────────────────────────┘

Note

git add doesn’t save anything yet — it just prepares changes. git commit is the actual save.

4. Starting a repository

Option A — Start from scratch (new project)

mkdir my-project
cd my-project
git init

This creates a hidden .git/ folder — that’s where Git stores everything.

Option B — Clone an existing repo from GitHub

git clone https://github.com/username/repository.git

# Clone into a specific folder name
git clone https://github.com/username/repository.git my-folder

Check the status of your repo at any time:

git status

5. Your first commit — step by step

Step 1: Create or modify a file

echo "# My Project" > README.md

Step 2: Check what Git sees

git status
# README.md is listed as "Untracked"

Step 3: Stage the file

git add README.md

# Stage ALL changed files at once
git add .

Step 4: Commit with a message

git commit -m "Add README file"

Writing good commit messages

A good commit message tells what changed and why, not how.

❌ Bad messages

  • fix
  • stuff
  • changes
  • asdfgh
  • final
  • final for real

✅ Good messages

  • Add login form validation
  • Fix crash when user list is empty
  • Remove deprecated API calls
  • Update README with install steps

Tip

Use the imperative mood: “Add feature” not “Added feature”.

6. Viewing history

See all commits:

git log

Compact one-line view (much nicer):

git log --oneline
# a3f1c2d Add login form
# 9b2e81a Fix crash on empty list
# 4c7a012 Initial commit

See what actually changed in each commit:

git log --oneline --stat

See changes not yet staged:

git diff

See changes already staged:

git diff --staged

7. Undoing things

Unstage a file (keep your edits):

git restore --staged filename.py

Discard all edits to a file (back to last commit):

git restore filename.py

Warning

git restore filename.py permanently discards unsaved changes. There’s no undo.

Undo the last commit (keep files intact):

git reset --soft HEAD~1

Fix the last commit message:

git commit --amend -m "Corrected commit message"

8. Branches

A branch is an independent copy of your project where you can work freely without affecting the main code.

main   ──●──●──●──────────────●──▶
                \            /
feature         ●──●──●──●──

Create and switch to a new branch:

git switch -c feature/login

List all branches:

git branch

Switch between branches:

git switch main
git switch feature/login

Delete a branch (after merging):

git branch -d feature/login

Merging branches

Once your feature is ready, merge it back into main:

# 1. Switch to the target branch
git switch main

# 2. Merge the feature branch into it
git merge feature/login

If there are no conflicts, Git merges automatically.

If there’s a conflict, Git marks the affected file:

<<<<<<< HEAD
print("Hello from main")
=======
print("Hello from feature")
>>>>>>> feature/login

Edit the file to keep what you want, remove the markers, then:

git add filename.py
git commit -m "Merge feature/login into main"

9. Working with remotes (GitHub / GitLab)

Add a remote to your local repo:

git remote add origin https://github.com/username/repo.git

Check your remotes:

git remote -v

Push your commits to GitHub for the first time:

git push -u origin main

Push after the first time:

git push

Pull latest changes from GitHub:

git pull

Typical daily workflow

# 1. Get the latest changes from teammates
git pull

# 2. Create a branch for your task
git switch -c feature/my-task

# 3. Do your work... edit files...

# 4. Check what changed
git status
git diff

# 5. Stage and commit
git add .
git commit -m "Implement my task"

# 6. Push to GitHub
git push -u origin feature/my-task

# 7. Open a Pull Request on GitHub and ask for review

10. The .gitignore file

Tell Git to ignore files you never want to commit (secrets, logs, build artifacts):

# Create the file at the root of your project
nano .gitignore

Example .gitignore for a Python project:

# Python
__pycache__/
*.pyc
*.pyo
.venv/
venv/
*.egg-info/

# Environment variables (NEVER commit these!)
.env

# Editor files
.vscode/
.idea/

# OS files
.DS_Store
Thumbs.db
git add .gitignore
git commit -m "Add .gitignore"

11. SSH keys — no more password prompts

Instead of typing your password every push, use an SSH key:

Step 1: Generate a key pair

ssh-keygen -t ed25519 -C "you@example.com"
# Press Enter to accept defaults

Step 2: Copy your public key

cat ~/.ssh/id_ed25519.pub
# Copy the entire output

Step 3: Add it to GitHub

GitHub → Settings → SSH and GPG keys → New SSH key → Paste → Save

Step 4: Test the connection

ssh -T git@github.com
# Hi username! You've successfully authenticated.

Step 5: Use SSH URLs instead of HTTPS

git remote set-url origin git@github.com:username/repo.git

Essential commands cheatsheet

Command What it does
git init Start a new repo
git clone <url> Copy a remote repo locally
git status Show current state
git add . Stage all changes
git commit -m "msg" Save a snapshot
git log --oneline View commit history
git push Upload to remote
git pull Download from remote
git switch -c <name> Create + switch branch
git merge <branch> Merge a branch
git restore <file> Discard file changes
git diff Show unstaged changes

Common mistakes and fixes

“I committed to main by accident”

git reset --soft HEAD~1      # Undo commit, keep changes staged
git switch -c feature/oops   # Move work to a new branch

“I accidentally deleted a file”

git restore deleted_file.py

“I need to see what the project looked like 3 commits ago”

git log --oneline            # Find the commit hash
git checkout a3f1c2d         # Look around (read-only)
git switch main              # Come back

“My push was rejected”

git pull --rebase            # Get remote changes first
git push                     # Now push your commits on top

Summary

The golden flow

  1. git pull — sync first
  2. git switch -c branch — work in isolation
  3. edit → git add .git commit
  4. repeat step 3
  5. git push — share your work
  6. open a Pull Request

The golden rules

  • Commit early and often
  • Write meaningful messages
  • Never commit .env or secrets
  • Always work on a branch
  • git status is your best friend

Tip

The best way to learn Git is to use it every day, even for personal projects. Break things, recover them — that’s how it clicks.