Git and GitHub for Beginners: Step-by-Step Guide

Alright, let’s get you set up with Git and GitHub. Ever had a project with ten different versions saved all over your desktop because you were afraid to lose your progress? I’ve been there too. Git keeps track of every change you make so you can go back if something breaks. GitHub gives your work a safe and organized home online, so you never have to dig through messy folders wondering which file is the real one.
In this beginner friendly guide, you’ll learn how to:
Install Git
Set up your identity
Create a project folder
Make your first commit
Push your project to GitHub
Step 1: How to Install Git and Configure Your Username & Email
Download Git from git-scm.com. Select your operating system (Windows, macOS, or Linux).
Follow the installer instructions, the default settings work fine for most people.
Once installed, open Git Bash (Windows) or your terminal (macOS/Linux). This is where you’ll type Git commands.
Run these commands to set your name and email. These will be linked to every commit you make.
git config --global user.name "Your Name"
git config --global user.email "youremail@example.com"
What’s happening here?
git config
: Sets Git configuration values.--global
: Applies settings to all projects on your machine.user.name
&user.email
: Identifies you in commit history.
Step 2: Create Your First Git Project Folder
Now that Git knows who you are, let us create the workspace where your code will live.
This is where you will initialize Git and start version control.
2. Creating a new folder and navigate into it
mkdir my-first-project
cd my-first-project
2. Initialize Git in the folder
git init
git init
: Converts the folder into a Git repository by creating a hidden.git
folder that tracks every change.You should never manually edit
.git
; it’s where Git stores its magic.
git init
in the root folder of your project so all files are tracked together.Step 3: Make Your First Git Commit
A commit in Git is like saving your project’s progress, but with a time machine.
Every commit stores what changed, when, and who made the change.
1. Open your project in a code editor
Open the folder in VS Code directly from Git Bash:
code .
This launches your project in VS Code so you can start editing.
2. Create your first file
Inside the editor, create a new file called
hello.txt
.Add the text:
Hello, Aliens and Viruses!
- Save the file.
3. Check your Git status
git status
What it does: Shows the current state of your Git repository.
Right now,
hello.txt
will be listed as untracked, meaning Git sees it but isn’t saving it yet.
4. Stage the file
git add hello.txt
- What it does: Adds the file to Git’s staging area, like a waiting room for changes before they’re saved.
5. Commit the change
git commit -m "Initial commit with hello.txt"
What it does: Saves your staged changes to the Git history with a descriptive message.
The
-m
flag lets you add the commit message inline.
Step 4: Push Your Project to GitHub
It’s time to take your project online.
Go to GitHub and create a new, empty repository. (Don’t add a README, license, or .gitignore yet.)
Copy the repository URL, it will look like:
https://github.com/your-username/your-repo-name.git
In Git Bash, connect your local repository to GitHub:
git remote add origin https://github.com/your-username/your-repo-name.git
Upload your commits to GitHub:
git push -u origin main
View Your Repository Online
Head to your GitHub repository page, you should see your file (hello.txt
) and commit message displayed. Congratulations, your project is now safely stored online and accessible from anywhere!💡Pro Tip: The-u
flag sets your localmain
branch to track the remotemain
branch. This way, future pushes only requiregit push
without specifying the branch or remote.
🎉 Congratulations — Your First Repository is Live!
You’ve successfully:
Installed and configured Git
Created your first project
Made your first commit
Pushed it to GitHub for the world (or just you) to see
Your GitHub repository is now your project’s safe, organized home in the cloud. No more messy folders or losing track of your changes — everything is versioned, backed up, and ready to share.
Subscribe to my newsletter
Read articles from Ananya Thakre directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
