Git is the tool that lets you track every change you make to your project — who changed what, when, and why. GitHub is where those changes live online so you can access them from anywhere, share them with others, or roll back to any earlier version.
Every developer uses Git, every day. This guide gets you from zero to your first pushed commit.
What is version control?
Without version control, you end up with folders like this:
project/
index.html
index-v2.html
index-FINAL.html
index-FINAL-v2.html
index-ACTUALLY-FINAL.html
Git replaces all of that. You keep one version of your files. Git tracks every change invisibly in the background, and you can jump back to any point in the history instantly.
Step 1: Install Git
On macOS
Open Terminal (press Cmd + Space, type "Terminal", press Enter).
Check if Git is already installed:
git --version
If you see a version number like git version 2.45.2, you're done. Skip to Step 2.
If not, install it with Homebrew. First install Homebrew if you don't have it:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
Then install Git:
brew install git
Verify:
git --version
On Windows
- Go to git-scm.com/download/win
- Download the latest 64-bit installer
- Run it — accept all default settings
- Open Git Bash (search for it in the Start menu)
- Verify:
git --version
Use Git Bash on Windows for all commands in this guide.
Step 2: Configure Git with your identity
Git attaches your name and email to every commit you make. Do this once:
git config --global user.name "Your Name"
git config --global user.email "[email protected]"
Replace with your actual name and the email you'll use for GitHub. Verify it saved:
git config --global --list
Step 3: Create a GitHub account
Go to github.com and sign up for a free account if you don't have one. Use the same email you set in Step 2.
Step 4: Create your first local project
Create a folder for your project:
mkdir my-first-project
cd my-first-project
Create a simple file inside it:
echo "# My First Project" > README.md
You now have a folder with one file in it.
Step 5: Initialise a Git repository
Tell Git to start tracking this folder:
git init
You'll see:
Initialized empty Git repository in /path/to/my-first-project/.git/
A hidden .git folder has been created. This is where Git stores all its tracking data. Don't touch it.
Step 6: Stage and commit your file
Check the status of your working directory:
git status
You'll see README.md listed as an "untracked file" — Git can see it exists but isn't tracking it yet.
Stage the file (tell Git to include it in the next commit):
git add README.md
To stage all files at once:
git add .
Commit the staged files with a message describing what you did:
git commit -m "Add README"
You'll see output like:
[main (root-commit) a3f1c2d] Add README
1 file changed, 1 insertion(+)
create mode 100644 README.md
That string (a3f1c2d) is your commit hash — a unique ID for this snapshot.
Step 7: Create a repository on GitHub
- Go to github.com/new
- Repository name:
my-first-project - Leave it Public (or Private — your choice)
- Do NOT tick "Add a README file" — you already have one
- Click Create repository
GitHub will show you a page with setup instructions. You only need the commands in the "push an existing repository" section.
Step 8: Connect your local project to GitHub
Copy the repository URL from the GitHub page. It looks like:
https://github.com/yourusername/my-first-project.git
Add it as the remote origin:
git remote add origin https://github.com/yourusername/my-first-project.git
Rename your current branch to main (GitHub's default):
git branch -M main
Step 9: Push to GitHub
git push -u origin main
Git will ask for your GitHub username and password. Note: GitHub no longer accepts your account password here — you need a Personal Access Token.
To create a token:
- Go to github.com/settings/tokens
- Click Generate new token (classic)
- Give it a name, set expiry, tick repo scope
- Copy the token — you won't see it again
Use the token as your password when Git prompts you.
After a successful push, refresh your GitHub repository page. Your README.md is there.
The daily Git workflow
Once your project is set up, your day-to-day workflow is:
# 1. Make changes to your files
# 2. See what changed
git status
# 3. Stage the changes
git add .
# 4. Commit with a message
git commit -m "Describe what you changed"
# 5. Push to GitHub
git push
After the first push with -u origin main, you only need git push from then on.
Commands you'll use most
| Command | What it does |
|---|---|
git status | Show what's changed and what's staged |
git add . | Stage all changed files |
git add filename | Stage one specific file |
git commit -m "message" | Save a snapshot with a description |
git push | Upload commits to GitHub |
git pull | Download latest changes from GitHub |
git log | Show commit history |
git log --oneline | Show commit history, condensed |
git diff | Show line-by-line changes not yet staged |
What to do when something goes wrong
Accidentally staged the wrong file:
git restore --staged filename
Want to undo your last commit (but keep the changes):
git reset HEAD~1
Check where your remote is pointing:
git remote -v
Clone an existing GitHub repository to your computer:
git clone https://github.com/username/repo-name.git
What to learn next
Once you're comfortable with add, commit, and push, the next things to learn are:
- Branching —
git checkout -b feature-nameto create a new branch - Merging — combining branches when work is done
- Pull requests — the GitHub workflow for proposing and reviewing changes
- .gitignore — a file that tells Git which files to never track (like
node_modules/or.env)
A good .gitignore for most projects:
node_modules/
.env
.DS_Store
*.log
dist/
Create it at the root of your project before your first commit.