If you have ever saved a file as report_final_v2_REAL_final.docx, you already understand why Git exists. It is the grown-up version of that habit: a tool that remembers every version of your work, lets you travel back in time, and lets a team edit the same project without overwriting each other. GitHub is where those projects usually live online. This guide explains both from zero.
The problem Git solves
I started programming long before Git was everywhere, and I remember what folders looked like in those days. site_backup, site_backup_old, site_NEW, site_NEW_fixed, and one called site_dont_touch. Nobody knew which was current. When a client said “the version from last Tuesday was better,” the honest answer was often “I think I overwrote it.”
Now picture a team of five editing the same files. Two people change the same paragraph. Someone emails a zip file. Someone else works from an older copy. Merging all of that by hand is miserable, and mistakes are guaranteed.
Version control is the fix. Instead of copying folders, you tell a tool when you have reached a meaningful point, and it stores a snapshot. The most popular version control system in the world is Git, created in 2005 by Linus Torvalds for the Linux kernel. Today it is used by solo students, small studios and the largest software companies alike.
The one-sentence version. Git is a tool on your computer that records snapshots of your project over time. GitHub is a website that stores your Git projects online so you can back them up, share them and collaborate.
Git vs GitHub: the part everyone mixes up
Beginners often use the two names as if they were one thing. They are not, and the difference matters.
- Git is software that runs on your own computer. It works offline. It does the actual tracking of changes.
- GitHub is a company’s website (owned by Microsoft) that hosts Git repositories in the cloud and adds features around them: pull requests, issue tracking, code review and project pages.
The analogy I use in workshops: Git is a camera, and GitHub is the photo-sharing site. You can take photos without ever uploading them, but the website makes it easy to back them up and show them to others. Similar sites exist, including GitLab and Bitbucket. They all speak Git.
| Question | Git | GitHub |
|---|---|---|
| What is it? | A version-control program | A hosting website and platform |
| Where does it run? | On your computer | Online, in the cloud |
| Needs internet? | No | Yes |
| Main job | Track and organise your changes | Store, share and review them with others |
| Alternatives | Mercurial, Subversion | GitLab, Bitbucket |
The vocabulary you need (and nothing more)
Git has a reputation for jargon. In reality, you need about eight words, and each has a plain-English meaning.
| Term | Plain meaning | Everyday analogy |
|---|---|---|
| repository | A project folder that Git tracks, with its full history | A filing cabinet with every past version |
| commit | A saved snapshot with a message | A save point in a video game |
| branch | A separate line of work | A parallel draft you can experiment in |
| merge | Combining one branch into another | Pasting your draft into the main document |
| clone | Copying a repository to your computer | Downloading the whole cabinet |
| remote | A copy of the repository hosted elsewhere | The cloud backup |
| push / pull | Send your commits up / bring others’ commits down | Upload and download |
| pull request | A request to merge your branch, with review | “Please check my work before it goes in” |
How a change travels through Git
This is the single most useful mental model in the whole subject, and almost every beginner tutorial skips it. A change passes through four places.
- Working folder: the files you see and edit on your computer.
- Staging area: a waiting room where you choose exactly which changes go into the next snapshot.
- Local repository: the saved history of commits, stored in a hidden
.gitfolder. - Remote (GitHub): the copy online that teammates can reach.
The staging area surprises people. Why not save everything at once? Because it lets you craft tidy commits. Imagine you fixed a typo and also started a risky new feature in the same afternoon. Staging lets you commit the typo fix by itself, with a clear message, and leave the unfinished feature for later.
Setting up: install and introduce yourself
Download Git from the official site (git-scm.com) or install it with your system’s package manager. Then check that it works.
git --version
Next, tell Git who you are. Every commit carries a name and email, so this is a one-time setup.
git config --global user.name "Your Name"
git config --global user.email "[email protected]"
git config --global init.defaultBranch main
The last line makes new repositories start with a branch called main, which matches what GitHub uses today. Older installs may still default to master, so setting it avoids confusion.
Your first repository, step by step
Let us track a small recipe collection. Open a terminal, make a folder and start Git inside it.
mkdir recipes
cd recipes
git init
Git replies with something like:
Initialized empty Git repository in /home/you/recipes/.git/
Now create a file called pasta.txt with three lines of text in any editor, then ask Git what it sees.
git status
On branch main
No commits yet
Untracked files:
(use "git add <file>..." to include in what will be committed)
pasta.txt
nothing added to commit but untracked files present (use "git add" to track)
“Untracked” means Git sees the file but is not recording it yet. git status is your best friend: run it constantly, especially when confused. Now stage the file and commit it.
git add pasta.txt
git commit -m "Add pasta recipe"
[main (root-commit) a1b2c3d] Add pasta recipe
1 file changed, 3 insertions(+)
create mode 100644 pasta.txt
Congratulations, you have made your first snapshot. The odd string a1b2c3d is the start of a commit’s unique ID. (Yours will look different; the examples here use made-up IDs.) Add a sauce recipe and a typo fix the same way, and your history looks like this.
git log --oneline
1f2e3d4 (HEAD -> main) Add dessert
7c8d9e0 Fix typo
e4f5a6b Add sauce
a1b2c3d Add pasta recipe
Every dot in that chain is a version you can return to. That is the whole magic: history becomes a thing you can read, search and travel through.
Writing commit messages people will thank you for
A commit message is a note to your future self, and to everybody else. Compare these two histories:
- “stuff”, “fix”, “fix 2”, “asdf”
- “Add login form validation”, “Fix crash when email is empty”, “Remove unused styles”
The second tells a story. A few habits help: write in the imperative (“Add”, not “Added”), keep the first line under about 50 characters, and describe what and why, not how. Six months later, when something breaks, you will be searching that history for answers, and clear messages turn a two-hour hunt into a two-minute one.
Telling Git what to ignore
Not every file belongs in version control. Passwords, API keys, temporary files and huge generated folders should stay out. Create a plain text file named .gitignore and list patterns.
.env
node_modules/
*.log
.DS_Store
This is more than tidiness. Never commit secrets such as API keys or passwords. Once something is pushed to a public repository, bots can find it within minutes. If it happens, rotate the key immediately. Deleting the file later does not erase it from history.
Branches: safe places to experiment
A branch is simply a movable label on a line of commits. Your main branch holds the version that works. When you want to try something, you create a new branch, work there, and leave main untouched.
git switch -c feature/bigger-portions
# edit files, then
git add pasta.txt
git commit -m "Increase pasta portion size"
Think of it as photocopying a document to scribble on, with the guarantee that the original stays clean. If the idea works, you merge it in. If it does not, you delete the branch and nothing is lost.
When you are ready, switch back to main and merge.
git switch main
git merge feature/bigger-portions
Merge conflicts are not scary
Sometimes two branches change the same line. Git cannot guess which you want, so it stops and asks you to decide. It marks the file like this.
<<<<<<< HEAD
Use 200g of spaghetti
=======
Use 250g of spaghetti
>>>>>>> feature/bigger-portions
The top part is your current branch, the bottom part is the incoming one. Edit the file to keep what you want (and delete the marker lines), then git add it and git commit. A conflict is just Git being polite and asking a question. In teams, conflicts become rare once people commit small changes often and pull regularly.
Bringing in GitHub
So far everything has lived on your computer. Now let us put it online. Create a free account at github.com, click the button to create a new repository, and name it recipes. GitHub will show you the web address of your empty repository. Connect your local project to it and upload.
git remote add origin https://github.com/YOU/recipes.git
git branch -M main
git push -u origin main
Here origin is just the nickname Git gives to your main remote. The -u flag remembers the connection so that later you can type only git push and git pull.
A practical note on logging in: GitHub no longer accepts your account password for Git operations over HTTPS. Use a personal access token, set up SSH keys, or install the GitHub CLI or Git Credential Manager, which handle sign-in for you. Their setup pages walk through it in a few minutes.
To get a project that already exists on GitHub onto your machine, you clone it.
git clone https://github.com/YOU/recipes.git
That downloads every file and the whole history, and sets up origin automatically.
Pull requests: how teams actually work
On a team, nobody pushes straight to main. Instead, the loop looks like this.
A pull request (often shortened to PR) is a page on GitHub that shows exactly what changed between your branch and main. Teammates can comment on specific lines, request changes and approve. When everyone is happy, someone clicks Merge. Automated checks, such as tests, can run on the PR too, so a broken change is caught before it reaches the shared code.
I have watched this process save projects. A new developer once pushed a change that would have deleted a customer table. Two people spotted it in review because the diff showed hundreds of red lines where there should have been five. Without a pull request, that change would have gone straight to production.
Five real situations, five workflows
Tap through the tabs. Each one shows a realistic scenario with the actual commands.
Solo project
You are writing a small recipe book as text files and want a safety net. No team, no internet needed.
git init
git add pasta.txt
git commit -m "Add pasta recipe"
git log --onelineWhy it works. Each commit is a snapshot you can return to. After a month of edits you can look back and see exactly when the sauce recipe changed, and why.
Undo mistakes
You edited the wrong file, or committed something you regret. Git has a different tool for each size of mistake.
# discard edits you have not committed
git restore pasta.txt
# take a file back out of the staging area
git restore --staged pasta.txt
# undo a commit by adding a new opposite commit
git revert 7c8d9e0Why it works. Use restore for uncommitted edits, and revert when the commit has already been shared, because it leaves history intact. Treat reset –hard as the sharp knife: it can throw work away.
Team feature
You and three colleagues are adding a search bar to a website. Nobody should break the working version.
git switch -c feature/search
# ...edit files...
git add .
git commit -m "Add search box"
git push -u origin feature/search
# open a pull request on GitHub, get a review, merge
git switch main
git pullWhy it works. Everyone works on their own branch, then proposes changes with a pull request. A teammate reads the changes before they reach main. That review step catches more bugs than most people expect.
Open source
You found a typo in a popular project’s documentation and want to fix it, but you are not a maintainer.
# click Fork on GitHub, then:
git clone https://github.com/YOU/project.git
cd project
git switch -c fix-typo
# fix the typo, then
git commit -am "Fix typo in README"
git push -u origin fix-typo
# open a pull request to the original projectWhy it works. A fork is your personal copy of someone else’s repository on GitHub. You change your copy and ask the owners to pull your change in. This is how thousands of strangers contribute to the same project.
Publish a site
You built a one-page portfolio and want it online without paying for hosting.
git add index.html
git commit -m "Launch portfolio"
git push origin main
# On GitHub: Settings, Pages, deploy from branch mainWhy it works. GitHub Pages serves static files straight from a repository. After setup, every push updates the live site. Your history doubles as a deployment log.
You will notice the same handful of commands appearing in every tab. That is the good news: the entire daily workflow of most developers is built from perhaps ten commands.
A beginner’s cheat sheet
| Command | What it does | When to use it |
|---|---|---|
| git status | Shows what has changed and what is staged | Constantly. Any time you are unsure. |
| git add <file> | Stages a file for the next commit | Before every commit |
| git commit -m “msg” | Saves a snapshot of staged changes | After each small, finished step |
| git log –oneline | Lists past commits in short form | To see history |
| git diff | Shows exact line changes not yet staged | Before staging, to review your work |
| git switch -c name | Creates and switches to a new branch | Starting a new task |
| git merge name | Merges a branch into the current one | Finishing a task locally |
| git push | Uploads commits to the remote | Sharing or backing up your work |
| git pull | Downloads and merges remote changes | Start of your working day |
| git clone <url> | Copies a remote repository to your computer | Joining an existing project |
| git restore <file> | Discards uncommitted edits to a file | When an experiment went wrong |
| git revert <id> | Undoes a commit by adding an opposite one | Undoing something already shared |
A daily routine you can copy
- Morning: run
git switch mainandgit pullso you start from the latest version. - Before starting a task: create a branch with
git switch -cand a descriptive name. - While working: run
git statusandgit diffoften, and commit each small finished step. - When done: push the branch and open a pull request.
- After the merge: switch back to main, pull, and delete the old branch.
It feels like a lot at first, and then one day you realise you have stopped thinking about it. That is when Git becomes a superpower instead of a chore.
Seven mistakes beginners make (tap to open)
1. Committing everything with a vague message
Messages like “update” tell nobody anything. Take ten seconds to describe the change. Your future self is the main beneficiary.
2. Committing secrets and API keys
Add sensitive files to .gitignore from day one. If a key leaks, revoke it immediately; deleting the file later does not remove it from history.
3. Working directly on main
Even solo, branches give you a safe place to experiment. On teams, working on main is how broken code reaches everyone.
4. Forgetting to pull before pushing
If a teammate has pushed since you last pulled, your push may be rejected. Pull first, resolve any conflicts, then push.
5. Using git reset –hard without thinking
It can destroy uncommitted work permanently. Prefer git restore for single files and git revert for shared commits unless you are certain.
6. Giant commits that mix unrelated changes
A commit with a bug fix, a refactor and a new feature is hard to review and hard to undo. Stage and commit them separately.
7. Panicking at a merge conflict
A conflict is a question, not a failure. Read the markers, choose what to keep, remove the markers, add, and commit.
Quick quiz: test yourself
Tap each question to reveal the answer and the reasoning.
What is the difference between Git and GitHub?
- They are the same thing
- Git is a website and GitHub is a program
- Git is the version-control tool on your computer, GitHub is an online home for Git repositories
- GitHub is only for photographers
Git tracks changes locally. GitHub hosts repositories online and adds collaboration features such as pull requests.
Which command moves changes from the working folder into the staging area?
- git add
- git commit
- git push
- git clone
git add stages changes. git commit then saves the staged snapshot into history.
You edited a file but have not committed. How do you throw those edits away safely?
- git push –force
- git restore <file>
- git merge
- git fork
git restore puts the file back to its last committed state. Be sure you want to lose those edits first.
What is a pull request?
- A command that downloads files
- A way to delete a branch
- A backup of your computer
- A proposal to merge your branch, with a place for review and discussion
A pull request asks the project to pull your changes in, and lets teammates review them first.
Which file stops Git from tracking things like passwords and build folders?
- README.md
- LICENSE
- .gitignore
- package.json
List patterns in .gitignore for files Git should leave alone. Secrets that were already committed need extra steps, so never commit them in the first place.
Frequently asked questions
Do I need GitHub to use Git?
No. Git works completely on your own computer. GitHub is optional, but it makes backup, sharing and teamwork much easier. GitLab and Bitbucket are alternatives.
What is a repository?
A repository, or repo, is a project folder that Git tracks, along with the full history of its changes stored in a hidden .git folder.
What is the difference between git pull and git fetch?
git fetch downloads new history from the remote without changing your files. git pull fetches and then merges it into your current branch.
What does git clone do?
It copies an entire repository from a remote location such as GitHub to your computer, including its history, and sets up the connection called origin.
How often should I commit?
Commit whenever you finish a small, meaningful step that you could describe in one sentence. Small commits are easier to review and easier to undo.
What if I committed a password by mistake?
Treat it as compromised: change the password or revoke the key right away. Removing it from history is a separate, harder job, so rotating the secret comes first.
The takeaway
Git remembers every version of your project, GitHub keeps a copy online and helps people work together, and the daily routine boils down to a few commands: status, add, commit, push, pull, and switch. You do not need to master everything. You need to commit small, write clear messages, work on branches and never commit secrets.
Make a practice repository today. Add three files, make five commits, create a branch, merge it, push it to GitHub. An hour of doing beats a week of reading, and you will never again have a folder called “final_v2_REAL_final.”

