Git and GitHub for beginners
Git saves snapshots of your project on your computer, and GitHub keeps them online so you can share them. Here's what each one is, the commands you'll use every day, and a first project from start to finish.

You're writing a long essay. You save copies as you go: essay.docx, essay-final.docx, essay-final-2.docx. A week later, you can't remember which copy has the good opening. Code has the same problem, only with dozens of files that change every day.
Git is a free tool that saves snapshots of your project, so you can see every change and go back to any earlier version. GitHub is a website that keeps Git projects online, so you can back them up, share them, and work on them with other people. This guide to Git and GitHub for beginners explains each one, the commands you'll use every day, and a first project from start to finish.
What is Git?
Git is a version control system: a program that keeps the history of your files. It runs on your own computer, and it works without the internet.
Each time you save a version in Git, it takes a snapshot of your whole project. That snapshot is called a commit. A commit works like a save point in a video game. If you break something later, you can look back at any save point or return to it.
A project that Git tracks is called a repository, or repo for short. It's a normal folder with one extra part. A hidden folder named .git holds all the snapshots.
Git is free and open source, so anyone can use it. You can download it from the official Git website.
What is GitHub?
GitHub is a website that stores Git repositories online. A copy of your repo that lives on another computer, like GitHub's, is called a remote.
GitHub also adds tools for working with other people. The biggest is the pull request: a page where you propose the changes on a branch, so others can review them before they're merged. There are also issues for tracking bugs and ideas, and GitHub Pages for publishing a website from a repo.
You can sign up for a free GitHub account. You don't need to pay for anything in this guide.
What is the difference between Git and GitHub?
Git is the tool. GitHub is a place to keep and share what the tool makes.
| Git | GitHub | |
|---|---|---|
| What it is | A program that tracks changes | A website that hosts Git repos |
| Where it runs | On your computer | In the cloud |
| Needs the internet | No | Yes |
| Works without the other | Yes | No, every repo on it is a Git repo |
So you can use Git with no GitHub at all. And GitHub isn't the only home for Git repos: GitLab and Bitbucket host them too.
How does Git save your work?
A change passes through three places before it's saved. Think of packing a box to mail. Your desk holds everything you're working on. The open box holds only what you've picked to send. Once you tape the box shut, it goes on the shelf for good.
- The working directory is your desk. It's the files in your folder, as you edit them.
- The staging area is the open box. It holds the changes you've picked for the next commit.
- The repository is the shelf. It keeps every commit you've made, inside
.git.

The staging area lets you save related changes together. Say you fixed a typo and also started a new page. You can commit the typo fix on its own and keep working on the page.
What are the basic Git commands?
These eleven commands cover everyday work. You type them in a terminal, a window where you run programs by typing their names. Setting up your tools shows how to open one.
| Command | What it does |
|---|---|
git init |
Turns the current folder into a new repository |
git status |
Shows which files changed and which are staged |
git add <file> |
Puts a change in the staging area |
git commit -m "message" |
Saves the staged changes as a commit, with a note |
git log |
Lists past commits, newest first |
git branch |
Lists your branches, or creates one |
git switch <branch> |
Moves you to another branch |
git merge <branch> |
Brings another branch's commits into the current one |
git push |
Sends your commits to a remote, like GitHub |
git pull |
Gets new commits from a remote and combines them with yours |
git clone <url> |
Copies a repository, with its history, to your computer |
A branch is a separate line of work. You can try an idea on a branch without touching the main version. If it works, you merge it back. If it doesn't, you delete the branch.
How do you start your first project with Git and GitHub?
First, install Git. Then tell it who you are. You only do this once on each computer.
git config --global user.name "Your Name"
git config --global user.email "you@example.com"
git config --global init.defaultBranch main
The first two lines put your name and email on every commit. The third names your first branch main, the same name GitHub gives new repositories.
1. Create a repository
mkdir my-site
cd my-site
git init
This makes a folder named my-site, moves into it, and starts a new repository there.
2. Make your first commit
Create an index.html file in the folder, with a heading in it. Then run:
git status
git add index.html
git commit -m "Add the home page"
git log --oneline
The status shows index.html as untracked: Git sees it but isn't keeping its history yet. After the add, the file is staged. After the commit, it's saved, and the log shows one line with a short ID and your message.
3. Try a branch
git switch -c new-heading
The -c option creates a branch named new-heading and moves you onto it. Now change the heading in index.html, and save that change on the branch:
git add index.html
git commit -m "Change the heading"
git switch main
git merge new-heading
The last two lines go back to main and bring in the branch's commit. Now main has both commits.
4. Put it on GitHub
On GitHub, create a new repository named my-site. Leave it empty, with no README, because your project already has commits. Then connect your folder to it and push:
git remote add origin https://github.com/YOUR-NAME/my-site.git
git push -u origin main
The first line saves GitHub's address under the name origin. The second sends your main branch there. The -u option makes Git remember the pair, so next time a plain git push is enough.
GitHub doesn't accept your account password in the terminal. An easy way to sign in is GitHub CLI. Install it, run gh auth login, choose HTTPS, and say yes when it offers to sign Git in.
5. Work from another computer
git clone https://github.com/YOUR-NAME/my-site.git
cd my-site
git pull
Clone copies the whole repo, with its history, onto a new computer. Later, a pull brings down any commits you pushed from somewhere else.
What mistakes do beginners make with Git?
- Committing without adding. A commit saves only what's staged. Run
git statusfirst, and it tells you what will go in. - Vague messages. A message like "stuff" won't help you in a month. Say what changed, like "Fix the menu on small screens."
- Saving secrets. An API key is a secret code that lets your app use another company's service. Anyone can read one pushed to a public repo. List files Git should skip in a file named
.gitignore: secrets like.env, and thenode_modulesfolder that npm can rebuild. - Doing everything on main. Make a branch for each new idea. Your main branch keeps working while you experiment.
- Thinking GitHub saves for you. GitHub only has what you've pushed. Commit often, and push when you finish something.
What should you learn after Git basics?
Put your repo to work. How to deploy a website for free turns my-site into a live page with GitHub Pages. VS Code has Git built in, and VS Code extensions for frontend developers covers what else to set up.
Then build something worth committing. Start the JavaScript course with Hello, world!, or try HTML, CSS, and JavaScript in the code editor, with nothing to install. Know some JavaScript already? What to learn after JavaScript basics maps out the next steps.


