TL;DR
- Git is a tool on your computer that tracks changes to your code. GitHub is a website that stores Git projects online.
- The daily routine is four commands:
git addโgit commitโgit push, andgit pullto get others' changes. - Work on a branch, then open a pull request so teammates can review before merging.
- You can have your first repo online in about 15 minutes. Follow the steps below.
Git vs GitHub: what's the difference?
People mix these up all the time. Think of writing a book:
Git = the history tool
Software installed on your computer. It saves a snapshot every time you ask it to, so you can go back to any earlier version. It works fully offline.
GitHub = the online home
A website that stores your Git projects in the cloud. It adds sharing, teamwork, code review and a public profile that shows your work.
You can use Git without GitHub. But almost everyone pairs them, because GitHub is where the code is backed up and where teams collaborate. (GitLab and Bitbucket are similar websites. Everything here works the same on them.)
The four places your code lives
Words you will hear
| Term | Meaning in plain English |
|---|---|
| Repository (repo) | A project folder whose history Git tracks. |
| Commit | A saved snapshot of your changes, with a short message describing it. |
| Branch | A separate line of work. Lets you try things without touching the main code. |
| Remote / origin | The online copy of your repo (on GitHub). origin is its default nickname. |
| Clone | Download a copy of a GitHub repo to your computer. |
| Fork | Your own copy of someone else's repo on GitHub, used to propose changes to it. |
| Push / Pull | Push uploads your commits to GitHub. Pull downloads others' commits to you. |
| Pull request (PR) | A request to merge your branch into another, so teammates can review first. |
| Merge | Combining the changes from one branch into another. |
| Issue | A task, bug or idea tracked on GitHub. |
Public vs private repositories
A public repo can be seen by anyone, which is great for a portfolio. A private repo is visible only to you and people you invite. Companies mostly use private repos for their work. Choose public for practice projects, and never put passwords or keys in either.
Set up in 5 steps
Create a GitHub account
Go to github.com and sign up for a free account. Pick a professional username, since it appears in your profile link and is what people see.
Install Git
Download Git from git-scm.com (Windows, macOS and Linux). On macOS, running the command below may offer to install it for you. Check that it worked:
$ git --version
# git version 2.xx.x
If you see a version number, you're ready. On Windows, the installer also gives you Git Bash, a terminal you can use for these commands.
Tell Git who you are
Git stamps your name and email on every commit. Use the same email as your GitHub account:
$ git config --global user.name "Your Name" $ git config --global user.email "you@example.com"
Connect your computer to GitHub
GitHub no longer accepts your account password for Git commands. Pick one of these:
- GitHub CLI (easiest): install it from cli.github.com, run
gh auth loginand follow the prompts in your browser. - SSH key: generate one with
ssh-keygen -t ed25519 -C "you@example.com"and add the public key under GitHub โ Settings โ SSH keys. - Personal access token: create one in GitHub settings and paste it when Git asks for a password over HTTPS.
Pick a place for your projects
Create a folder for your code so you always know where to find it:
$ mkdir projects $ cd projects
Your first repo: create, commit, push
We will create a repo on GitHub, bring it to your computer, change a file and send it back.
A. Create the repo on GitHub
- Click the + icon (top right) โ New repository.
- Name it
hello-github. - Choose Public, tick Add a README file, and click Create repository.
B. Clone it to your computer
Click the green Code button, copy the URL, then run:
$ git clone https://github.com/YOUR-USERNAME/hello-github.git $ cd hello-github
C. Make a change
$ echo "My first change" >> notes.txt
$ git status
# Untracked files: notes.txt
git status is your best friend. It tells you what changed and what to do next. Use it often.
D. Stage, commit and push
$ git add notes.txt
$ git commit -m "Add notes file"
$ git push
Refresh your repo page on GitHub. Your file and commit message are there. You just pushed your first commit! ๐
E. Getting changes back: pull
If a teammate (or you, from another computer) pushes changes, bring them down with:
$ git pull
git pull before you start work each day, so you begin from the latest code.Starting from a project you already have?
If your code is already on your computer, turn the folder into a repo and connect it to a new, empty GitHub repo:
$ git init
$ git add .
$ git commit -m "First commit"
$ git branch -M main
$ git remote add origin https://github.com/YOUR-USERNAME/my-project.git
$ git push -u origin main
Try it: see where your files go
๐งช The 4 zones, interactive
Click the buttons in order and watch a file move from your folder to GitHub.
Branches and pull requests: how teams work
In a team, nobody edits the main code directly. Instead, everyone works on their own branch, then asks for their work to be reviewed and merged through a pull request.
The full routine looks like this:
$ git pull # start from the latest main $ git switch -c add-contact-page # create and move to a new branch # ...edit files... $ git add . $ git commit -m "Add contact page" $ git push -u origin add-contact-page
Then on GitHub:
- You will see a banner "Compare & pull request". Click it.
- Write a short title and a description of what you changed and why.
- A teammate reviews it, may leave comments, and approves.
- Click Merge pull request. Your work is now part of
main.
Finally, tidy up locally:
$ git switch main $ git pull
Contributing to someone else's project
You usually can't push directly to a project you don't own. The open-source way is: fork the repo (your own copy on GitHub) โ clone your fork โ make a branch โ push โ open a pull request to the original project.
Command cheat sheet
| Command | What it does |
|---|---|
git clone <url> | Download a repo from GitHub |
git status | See what changed |
git add <file> / git add . | Stage one file / stage everything |
git commit -m "message" | Save a snapshot with a message |
git push | Upload commits to GitHub |
git pull | Download and apply others' changes |
git log --oneline | See the commit history |
git diff | See exactly what you changed |
git switch -c <name> | Create and move to a new branch |
git switch <name> | Move to an existing branch |
git branch | List branches |
Common problems (and easy fixes)
"Push rejected" or "failed to push"
Someone pushed before you. Run git pull first, then git push again.
Merge conflict
Two people changed the same lines. Git can't choose, so it marks both versions in the file. Open the file, keep the correct lines, delete the markers (<<<<<<<, =======, >>>>>>>), then git add and git commit. It looks scary the first time and becomes routine quickly.
Committed something you shouldn't have
Add private files such as .env or node_modules/ to a file named .gitignore so Git skips them. If you ever commit a password or key, treat it as leaked and change it right away. Deleting the file in a later commit does not remove it from history.
Writing good commit messages
- Short and specific:
Fix login button alignment, notchanges. - Start with a verb: add, fix, update, remove.
- One logical change per commit.
FAQ
What is the difference between Git and GitHub?
Git is a version control tool that runs on your computer. GitHub is a website that hosts Git repositories online so you can back them up, share them and collaborate.
What is a repository?
A repository, or repo, is a project folder whose history of changes is tracked by Git.
Clone vs fork: what's the difference?
Cloning copies a repo from GitHub to your computer. Forking creates your own copy of someone else's repo on GitHub, usually so you can propose changes.
What is a pull request?
A request to merge your changes from one branch into another, giving teammates a chance to review them first.
Is GitHub free?
Yes. The free plan includes unlimited public and private repositories for individuals. Paid plans add extra features.
Do I need to use the command line?
No. Tools such as GitHub Desktop and the Git features in VS Code let you do the same things with buttons. Learning the commands once helps you understand what those buttons do.