Ubuntu 24.04 · Git 2.x · SSH Auth

Master Git & GitHub
from Scratch

Everything you need to upload, update, and manage your projects safely — HTML, CSS, JavaScript, Python, and isolated environments. Never lose your work again.

01

Install & Configure Git

Run these commands only once on your machine. After this, every project uses the same identity.
1
Install Git
terminal
$sudo apt install git
$git --version
git version 2.43.0
2
Set your identity (shown in all commit history)
terminal
$git config --global user.name "your name"
$git config --global user.email "your@email.com"
$git config --global init.defaultBranch main
# confirm your settings
$git config --list

Use the same email as your GitHub account.

02

SSH Key Setup

SSH authenticates you automatically — no password every time you push. Do this once, then forget it exists.

1
Generate your key
terminal
# press Enter 3× for all defaults (no passphrase needed)
$ssh-keygen -t ed25519 -C "your@email.com"
# print the public key — copy everything printed
$cat ~/.ssh/id_ed25519.pub
ssh-ed25519 AAAAC3Nz... your@email.com
2
Add to GitHub

Go to github.com → Settings → SSH and GPG keys → New SSH key, paste the full output from above, save.

3
Test the connection
terminal
$ssh -T git@github.com
Hi Sir! You've successfully authenticated...

That green line means it works. You're done with SSH forever.

03

How Git Works — The Mental Model

Git has 4 zones. Every command moves your files between them.

Working Dir
your files
Staging
git add
Local Repo
git commit
GitHub
git push

Working Directory

Your actual folder on disk — the files you edit in VSCode or PyCharm. Git sees changes here but hasn't recorded them yet.

Staging Area

A holding zone. You choose exactly which changes go into the next commit. git add file.html moves something here.

Local Repository

The full history of your project, stored inside the hidden .git folder. git commit saves a permanent snapshot.

GitHub (Remote)

The copy on the internet. git push syncs your local commits up. git pull brings remote changes down.

04

First Upload — The Safe Way

The mistake that loses your work: Creating a repo on GitHub first, then cloning it into your existing project folder. The clone overwrites everything. Always go Local → GitHub, never GitHub → Local for first upload.

✗ Wrong order

  • Create repo on GitHub with README
  • git clone → into existing project folder
  • 🔥 Your files get deleted or mixed up

✓ Correct order

  • Start from your local project folder
  • git init → add → commit
  • Create EMPTY repo on GitHub (no README)
  • git remote add → git push
1
Go into your project folder
terminal
$cd ~/Projects/my-project
# confirm you are in the right place
$ls
2
Create .gitignore — before anything else
terminal
$nano .gitignore

See the interactive .gitignore builder in section 07 to generate the right content.

3
Initialize, stage, and commit
terminal
$git init
Initialized empty Git repository in .git/
$git add .
$git commit -m "first commit"
4
Create an EMPTY repo on GitHub — then connect it

On GitHub: New repo → give it a name → leave all checkboxes UNCHECKED → Create. Copy the SSH URL (starts with git@github.com:...).

terminal
$git remote add origin git@github.com:USERNAME/repo-name.git
$git branch -M main
$git push -u origin main
Branch 'main' set up to track remote branch 'main' from 'origin'.

Done. Refresh GitHub — your project is there. The -u flag means future pushes only need git push.

05

Daily Workflow — Add, Commit, Push

After the first upload, this is all you need every day. Always start with git status before anything else.
daily workflow
# 1 — see what changed
$git status
# 2 — stage everything (or a single file)
$git add .
$git add index.html # specific file
# 3 — commit with a meaningful message
$git commit -m "add login page with validation"
# 4 — push to GitHub
$git push
main -> main

Good commit messages

"add contact form"
"fix navbar on mobile"
"update portfolio images"

"update" ✗
"fix" ✗
"asdf" ✗

Check history

See all your snapshots anytime:

git log --oneline
git log
git diff HEAD~1

Undo last commit

If you commit by mistake — before pushing:

git reset HEAD~1

This keeps your files, just removes the commit.

06

Branches — Work Without Breaking Things

A branch is a parallel version of your project. You experiment on a branch — if it works, you merge it into main. If it fails, you delete the branch and nothing is harmed.

branches — basics
# see all branches (current shown with *)
$git branch
* main
# create a new branch and switch to it
$git checkout -b feature/new-page
# switch between existing branches
$git checkout main
$git checkout feature/new-page
branches — merge
# first go back to main
$git checkout main
# merge your feature branch into main
$git merge feature/new-page
# delete the branch after merging (cleanup)
$git branch -d feature/new-page
branches — remote
# push a branch to GitHub
$git push -u origin feature/new-page
# see all remote branches
$git branch -r
# delete a branch on GitHub
$git push origin --delete feature/new-page
07

.gitignore Builder

Click what applies to your project — your .gitignore is generated below. Copy it into a file named .gitignore at the root of your project.

Python / venv
venv/ __pycache__/ *.pyc
Secrets / .env
.env secrets.py
Node.js
node_modules/ dist/
VSCode
.vscode/
PyCharm / JetBrains
.idea/ *.iml
OS files
.DS_Store Thumbs.db
Editor backups
*.html~ *~ *.bak
Archives
*.zip *.tar.gz
Cache & logs
.cache/ *.log tmp/
Databases
*.sqlite3 *.db

Generated .gitignore:

08

Python & Isolated Environments

!
Never push your venv folder to GitHub. It's hundreds of MB, machine-specific, and rebuilds in seconds. Push requirements.txt instead.
1
Create a venv inside each project folder
terminal
$cd ~/Projects/my-python-project
$python3 -m venv venv
$source venv/bin/activate
(venv) $ ← prompt shows you're inside the env
(venv) $ pip install flask pandas requests
2
Save the package list before pushing
terminal
$pip freeze > requirements.txt
$git add requirements.txt
$git commit -m "add requirements.txt"
$git push
3
Recreate the environment on any machine
terminal
$python3 -m venv venv
$source venv/bin/activate
$pip install -r requirements.txt

✓ Push to GitHub

  • All .py / .html / .js / .css files
  • requirements.txt
  • .gitignore
  • README.md

✗ Never push

  • venv/ folder
  • __pycache__/
  • .env (secrets, API keys)
  • *.sqlite3 database files
09

Working With Existing Repos

!
Only clone into an empty folder. Never clone into a folder that already has project files.
clone
# clone creates a new folder — go to parent dir first
$cd ~/Projects
$git clone git@github.com:USERNAME/repo-name.git
# this creates ~/Projects/repo-name/ automatically
$cd repo-name
pull updates
# download latest changes from GitHub into your local copy
$git pull
# see what's different before pulling
$git fetch
$git diff origin/main
remotes
# check what remote your project is connected to
$git remote -v
origin git@github.com:USER/repo.git (fetch)
origin git@github.com:USER/repo.git (push)
# where is the .git root? (never should be your home dir!)
$git rev-parse --show-toplevel
# change remote URL
$git remote set-url origin git@github.com:USER/new-repo.git
10

Fix Common Mistakes

fix
# fix the last commit message (before pushing)
$git commit --amend -m "correct message here"
fix
# remove a file from staging (keep the file unchanged)
$git restore --staged secrets.py
# remove everything from staging
$git restore --staged .
fix
# undo last commit — keeps your file changes
$git reset HEAD~1
# undo last commit AND discard file changes (destructive!)
$git reset --hard HEAD~1
!
Only force-push on your own projects. Never on shared team repos.
fix
# undo the commit locally
$git reset HEAD~1
# force push to overwrite GitHub's history
$git push --force
Danger zone. If your .git is in the wrong place (home dir or parent folder), the fix is to remove it and re-init inside the correct project folder.
fix wrong .git location
# 1 — find where your .git actually is
$git rev-parse --show-toplevel
# 2 — undo bad push if needed
$git reset HEAD~1
$git push --force
# 3 — remove the misplaced .git folder
$rm -rf /wrong/path/.git
# 4 — go into the correct project folder and re-init
$cd ~/Projects/my-project
$git init
$git remote add origin git@github.com:USER/repo.git
$git fetch origin
$git reset --soft origin/main
$git add . && git commit -m "fix repo structure"
$git push --force origin main
11

Command Cheatsheet

Command What it does When to use
git statusShow changed/staged/untracked filesBefore every add or commit
git add .Stage all changesReady to commit everything
git add <file>Stage one specific fileCommitting partial work
git commit -m "msg"Save a snapshot with a messageAfter staging
git pushUpload commits to GitHubAfter committing
git pullDownload latest from GitHubBefore starting work
git log --onelineSee compact commit historyReview what's been done
git diffShow line-by-line changesBefore staging
git branchList branchesKnow where you are
git checkout -b nameCreate & switch to branchStarting new feature
git merge <branch>Merge branch into currentFeature complete
git stashTemporarily save uncommitted workNeed to switch branch fast
git stash popRestore stashed workBack on your branch
git reset HEAD~1Undo last commit (keep files)Committed too soon
git remote -vShow GitHub connectionDebugging push issues
git rev-parse --show-toplevelShow where .git root isDiagnosing repo problems