Git & GitHub Guide
Clone, commit, push, branch & merge — every Git command with examples.
A free, beginner-friendly Git and GitHub guide on one long, searchable page. Learn how to clone a repository, stage and commit changes, push to GitHub, and create, check, switch and merge branches — plus pulling, fetching, stashing, undoing commits, resolving merge conflicts, .gitignore, tags and pull requests. Every command is explained in plain English with a copy-ready line and a real worked example (with terminal output). Search “undo commit”, “new branch” or “push” to jump straight to it. Runs fully in your browser, no sign-up, no API.
Frequently asked questions
What is the difference between Git and GitHub?
Git is the version-control tool that runs on your computer and tracks changes to your files. GitHub is an online service that hosts your Git repositories so you can back them up, share them and collaborate. In short: Git is the software, GitHub is the website where your Git projects live.
How do I clone a repository from GitHub?
Run git clone followed by the repository URL — for example, git clone https://github.com/user/repo.git. This downloads a full copy of the repo, including its entire history, into a new folder on your computer. Then use cd <repo-name> to move into it and start working.
How do I commit and push my changes?
First stage your changes with git add . (or git add <file>), then commit them with git commit -m "your message", and finally upload them to GitHub with git push. If it is a brand-new branch, the first push needs git push -u origin <branch-name>.
How do I check which branch I'm on and switch branches?
Run git branch to list your branches — the current one is marked with a *. To move to another branch use git switch <branch-name> (or the older git checkout <branch-name>). To create a new branch and switch to it in one step, use git switch -c <branch-name>.
How do I create a new branch?
Use git switch -c <branch-name> (modern) or git checkout -b <branch-name> (works on every version) to create a branch and move onto it immediately. To only create it without switching, run git branch <branch-name>.
How do I merge two branches?
Switch to the branch you want to merge into (usually main) with git switch main, then run git merge <branch-name>. Git combines the commits. If the same lines were changed on both branches you'll get a merge conflict — edit the marked file, remove the conflict markers, then git add and git commit to finish.
What is a merge conflict and how do I fix it?
A merge conflict happens when the same lines in a file were changed differently on two branches, so Git can't decide which to keep. It marks the file with <<<<<<<, ======= and >>>>>>>. Open the file, keep the correct version, delete those markers, then run git add <file> and git commit to complete the merge. To cancel entirely, use git merge --abort.
How do I undo my last commit?
If you haven't pushed it, run git reset HEAD~1 to undo the commit while keeping your changes in the working files. If you have already pushed and shared it, use git revert <commit-hash> instead — it safely creates a new commit that reverses the old one without rewriting history.
What does git push -u origin main do?
It pushes your main branch to the remote named origin (your GitHub repo) and the -u flag links your local branch to it, so from then on a plain git push and git pull are enough for that branch. You typically need it only the first time you push a new branch.
Do I need to memorise all these commands?
No. In daily work you mostly use a handful: git pull, git add, git commit, git push, git status, and the branch/switch commands. Bookmark this page and use the search box to look up anything else — clone, merge, stash or undo — the moment you need it.
Is this Git and GitHub guide free to use?
Yes — it is 100% free with no sign-up, no login and no limits. The whole guide runs in your browser, so you can read every command, copy the examples and search anything without creating an account or installing anything.
How do I use Git and GitHub as a beginner?
Start with four commands in order: git clone <url> to download a repo (or git init to start a new one), git add . to stage your changes, git commit -m "message" to save them, and git push to upload them to GitHub. Once those feel natural, add branching (git switch -c <name>) and merging. This page explains each with a copy-ready example.
How do I push my code to GitHub for the first time?
Create an empty repository on GitHub, then in your project run: git init, git add ., git commit -m "first commit", git remote add origin <repo-url>, and finally git push -u origin main. The -u flag links your local branch to GitHub, so after this a plain git push is enough.
How do I create a new repository on GitHub and connect my local project?
On GitHub click New repository and copy its URL. In your local project folder run git init (if it isn't a repo yet), then git remote add origin <repo-url> to connect it, and push with git push -u origin main. Use git remote -v to confirm the remote was added correctly.
What is the difference between git fetch and git pull?
git fetch only downloads the latest changes from GitHub without touching your working files — it lets you review what changed first. git pull does the same download but immediately merges those changes into your current branch. In short: git pull = git fetch + git merge.
What is the difference between git switch and git checkout?
Both can move you between branches, but git switch is the newer, clearer command made only for branches (git switch <name>, or git switch -c <name> to create one). git checkout is older and does more — it can switch branches and also restore files — which made it confusing, so switch is now recommended for branch work.
How do I delete a branch in Git?
Delete a local branch with git branch -d <branch-name> (use -D to force-delete one that isn't merged yet). To remove the branch from GitHub as well, run git push origin --delete <branch-name>. You can't delete the branch you're currently on, so switch to main first.
Related tools — Guides & Tutorials
- Excel Cheat Sheet — Every essential Excel shortcut & top formula on one page.
- Excel Guide — How Excel works — the fundamentals, explained simply.
- Beginner Excel — Everyday Excel skills — with step-by-step examples.
- Advanced Excel — Lookups, dropdowns, duplicates & PivotTables — with examples.
- Master Excel — Dynamic arrays, Power Query, macros & dashboards.