// complete beginner's guide

Master
Git &
GitHub

From zero to pushing your first code online. Everything you need, nothing you don't.

9
Steps
3
Core commands
Projects you'll ship
// 01 — fundamentals

Key concepts

Before touching the terminal, understand what these words mean. It all clicks much faster.

{ }
Git
A free tool that tracks every change you make to your code. Lives entirely on your computer — not online.
GitHub
A website that hosts your Git repositories online. Think of it as Google Drive — but for code.
📦
Repository
A project folder that Git is tracking. Contains all your files plus the entire history of changes.
git init
📸
Commit
A snapshot of your project at a specific moment. Every commit has a message describing what changed.
git commit
🎭
Staging
Choosing which changed files to include in your next commit. Like packing a box before shipping it.
git add
🌿
Branch
A parallel version of your project. The default is called main. Branches let you experiment safely.
git branch
Push
Uploading your local commits to GitHub so they're backed up and shareable with the world.
git push
Pull
Downloading commits from GitHub onto your computer. Used when working with others or on multiple devices.
git pull
// 02 — mental model

How code moves

Every file goes through these four states before landing on GitHub.

Zone 01
Working Directory
your files on disk

Where you write and edit code. Git watches this folder but doesn't track changes until you say so.

Zone 02
Staging Area
git add .

A waiting room. Files here are ready to be committed. You can add or remove files before committing.

Zone 03
Local Repository
git commit -m "msg"

Staged files are saved as a permanent snapshot. This history lives on your computer.

Zone 04 — target
GitHub
git push origin main

Your commits are uploaded to GitHub. Now they're safe, backed up, and shareable.

// 03 — step by step

The full process

Follow these steps in order. Each one builds on the last.

01
setup — once ever
Install Git
Download Git from git-scm.com and install it. Then verify it worked by checking the version.
# Check that Git is installed
git --version

# Expected output:
git version 2.x.x
💡 On Mac: running the command above may trigger an automatic install prompt. On Windows: Git installs a "Git Bash" terminal — use that instead of Command Prompt.
02
setup — once ever
Configure your identity
Git labels every commit with your name and email. Use the same email address as your GitHub account.
git config --global user.name "Your Full Name"
git config --global user.email "you@example.com"

# Verify it saved correctly
git config --global --list
--global applies to all projects
03
per project
Create a GitHub repository
Go to github.com, click the + icon in the top right → New repository. Fill in:
Repository name A short, lowercase name with dashes (e.g. my-first-project)
Visibility Public (anyone can see) or Private (only you)
README Leave unchecked — you'll add files from your computer
💡 After creating the repo, copy the HTTPS URL shown — it looks like https://github.com/yourusername/my-first-project.git. You'll need it in step 5.
04
per project
Open your project in the terminal
Navigate into your project folder using the cd command (change directory).
# Mac / Linux
cd ~/Desktop/my-first-project

# Windows
cd C:\Users\YourName\Desktop\my-first-project

# Confirm you're in the right folder
ls   # Mac/Linux — or use: dir on Windows
💡 Shortcut: on Mac, right-click the folder in Finder → "New Terminal at Folder". On Windows, shift+right-click → "Open PowerShell window here".
05
per project
Initialize Git & connect to GitHub
Start Git tracking in your folder, then link it to the GitHub repo you created in step 3.
# Start tracking this folder with Git
git init

# Connect to your GitHub repo (paste your URL)
git remote add origin https://github.com/yourusername/my-first-project.git

# Verify the connection
git remote -v
origin = GitHub's nickname add remote = link
06
every time you save work
Stage your files
Tell Git which files to include in the next snapshot. The dot means "everything in this folder".
# Stage everything
git add .

# Or stage a specific file only
git add index.html

# See what's staged and what's not
git status
💡 Run git status before and after adding files — it shows exactly what Git sees in green (staged) vs red (not staged).
07
every time you save work
Commit your snapshot
Save the staged files as a permanent checkpoint with a short descriptive message.
git commit -m "Add homepage layout"

# View your commit history
git log --oneline
Good commit messages
"Add login form"
"Fix header spacing on mobile"
"Update README with setup steps"
"stuff"
"asdfgh"
"final final FINAL"
08
every time you save work
Push to GitHub
Upload your commits from your computer to GitHub. The -u flag saves the destination so future pushes are just git push.
# First push (sets the default destination)
git push -u origin main

# All future pushes — just this
git push
GitHub no longer accepts your account password. You need a Personal Access Token (PAT). Go to: GitHub → Settings → Developer Settings → Personal access tokens → Generate new token. Use this token as your password when prompted.
you made it
Your code is live on GitHub
Visit your GitHub repo URL to see your files. From now on, every time you make changes, the flow is just three commands:
# The everyday Git workflow
git add .
git commit -m "Describe what you changed"
git push
// 04 — reference

Command cheatsheet

Every command you'll actually use as a beginner.

Setup
git --versionCheck Git is installed
git config --global user.name "..."Set your name
git config --global user.email "..."Set your email
Starting a project
git initStart Git in current folder
git remote add origin <url>Link to GitHub repo
git clone <url>Copy a repo from GitHub
Daily workflow
git statusSee what changed
git add .Stage all changes
git add <file>Stage one file
git commit -m "msg"Save a snapshot
git pushUpload to GitHub
git pullDownload from GitHub
Inspecting history
git logFull commit history
git log --onelineCompact history
git diffSee unstaged changes
Undoing things
git restore <file>Discard file changes
git restore --staged <file>Unstage a file
git revert <hash>Undo a past commit safely
Branches
git branchList all branches
git branch <name>Create a new branch
git checkout <name>Switch to a branch
git merge <name>Merge branch into current
// 05 — troubleshooting

Common errors

Hit a wall? These are the most common beginner errors and how to fix them.

Error
remote: Support for password authentication was removed
GitHub stopped accepting passwords in 2021.
Fix
Create a Personal Access Token (PAT) and use it as your password. Go to GitHub → Settings → Developer Settings → Personal access tokens.
Error
error: failed to push some refs to origin
GitHub has commits your local machine doesn't have.
Fix
Pull first, then push:
git pull origin main
git push
Error
fatal: not a git repository
You ran a git command outside of a tracked folder.
Fix
Make sure you're inside your project folder with cd, then run git init if you haven't already.
Error
CONFLICT (content): Merge conflict in file.txt
Two versions of the same file have conflicting changes.
Fix
Open the conflicted file, look for <<<<<<< markers, choose which version to keep, delete the markers, then run git add . and git commit.
Error
src refspec main does not match any
You haven't made any commits yet, so there's nothing to push.
Fix
Make at least one commit first:
git add .
git commit -m "initial commit"
git push -u origin main
Error
Your branch is behind 'origin/main' by N commits
Someone else pushed to GitHub and you don't have their changes.
Fix
Run git pull to download and merge their changes before continuing your work.