A complete beginner's guide — from Git setup to hosting your site live with GitHub Pages
G-Tech Blog | 2026Uploading your website to GitHub is a great way to store your code online, share it with others, and even host it for free using GitHub Pages. This complete step-by-step guide will walk you through the entire process — even if you are completely new to Git and GitHub. By the end, your website will be live on the internet and you will understand the core workflow that professional developers use every single day.
GitHub is one of the most widely used platforms in software development. At its core, it is an online service that stores code using a version control system called Git. Think of it like Google Drive, but designed specifically for code — with powerful tools for tracking every change, collaborating with others, and managing multiple versions of a project at the same time.
For beginners, GitHub is particularly valuable because it provides completely free website hosting through a feature called GitHub Pages. You can put your portfolio, personal project, or school assignment live on the internet without paying anything for a server. Developers at every skill level — students, freelancers, and engineers at major tech companies — use GitHub as the central hub for their work.
Beyond code storage, a GitHub profile is increasingly important for anyone pursuing a career in tech. When you apply for jobs, internships, or freelance contracts, employers and clients regularly check your GitHub profile as evidence of your real skills. Every project you push and every commit you make builds your developer identity online. Starting to use GitHub now — even on small beginner projects — is one of the best habits you can build.
Track every change to your code and revert to any earlier version if something breaks.
Publish any static website live on the internet for free using GitHub Pages.
Work with teammates on the same codebase without overwriting each other's changes.
Show employers real, working code that proves your abilities better than any resume.
Many beginners confuse Git and GitHub. They are closely related but they are not the same thing. Understanding the difference will make this entire guide make much more sense.
Git is a tool you install on your own computer. It runs in your terminal and is responsible for tracking changes in your code, creating save points (called "commits"), and managing different versions of your project. Git works entirely on your local machine — it does not require an internet connection.
Git was created by Linus Torvalds in 2005 — the same engineer who created the Linux operating system. It is free, open-source, and runs on Windows, Mac, and Linux.
GitHub is a website that stores your Git-tracked projects online in the cloud. It's where your code lives so it is safely backed up, accessible from any device, and shareable with others or the public. GitHub is the largest code hosting platform in the world with over 100 million registered developer accounts.
GitHub was founded in 2008 and acquired by Microsoft in 2018. Popular alternatives include GitLab and Bitbucket, but GitHub remains the dominant choice in the industry.
The simplest way to remember it: Git is the tool, GitHub is the storage. You use Git commands on your computer to manage your code locally, then "push" (upload) that code to GitHub where it lives online. Every command you will type in this guide is a Git command — GitHub is simply the destination where the result ends up.
Before you start, make sure you have the following in place:
index.html filegit --version
If you see output like git version 2.43.0, Git is installed and ready to use. If you get an error
or "command not found," download Git for free from git-scm.com. The installer works on
Windows, Mac, and Linux, and the default installation options are fine for beginners.
When creating your GitHub account, take a moment to also add a profile photo and a short bio once you are signed in. Your GitHub profile is your developer identity — a clean, professional profile creates a strong first impression on employers, collaborators, and anyone who finds your work through search.
A repository (often shortened to "repo") is GitHub's version of a project folder. Every project you upload needs its own repository. Before you can push any code, you must create an empty repository on GitHub to serve as the destination.
my-website or
portfolio-site
After creating, GitHub shows a setup page. Look for the repository URL — it looks like
https://github.com/yourusername/my-website.git. Keep this page open; you will need the URL in
Step 7.
personal-portfolio,
weather-app, recipe-blog.
All Git commands are entered into a terminal (also called the command line or command prompt). Before running any Git commands, you must navigate your terminal into your website's folder — otherwise Git has no way of knowing which project you are referring to.
Press Windows + R, type cmd, and press Enter. Alternatively, search "Command
Prompt" in the Start menu. For the best experience on Windows, use Git Bash — a terminal that
is installed alongside Git and behaves identically to Mac/Linux terminals.
Press Command + Space to open Spotlight, type "Terminal," and press Enter. Or go to Applications
— Utilities — Terminal.
Press Ctrl + Alt + T, or search "Terminal" in your applications launcher.
Use the cd command ("change directory") to move into your project folder:
cd C:\Users\YourName\Desktop\my-website
cd ~/Desktop/my-website
Replace my-website with your actual folder name. To confirm you are in the right place, list the
files:
# Mac/Linux: list files
ls
# Windows: list files
dir
You should see your website files — like index.html, style.css,
script.js — printed in the output.
cmd, and press Enter — a command prompt opens directly inside that folder.cd (with a trailing space) in Terminal, then drag your project folder
from Finder into the Terminal window. The path fills in automatically. Press Enter to navigate there.
Now that your terminal is inside your project folder, you need to tell Git to start tracking it. This is called "initializing" a repository. You only do this once per project — never again for the same project.
git init
This command creates a hidden folder called .git inside your project directory. That folder is
where Git stores your entire project history — every commit, every change, every branch. You should never
manually edit or delete this .git folder; doing so would permanently destroy your version history.
After running the command you will see a message like: "Initialized empty Git repository in /your/folder/.git/". Your folder is now a Git repository. Git is aware of it — but it has not tracked any files yet. That's what the next step is for.
git init only once per project. Running it again inside the same folder is
harmless — Git will just reinitialize. However, never run git init inside a folder that is
already nested inside another Git repository — this creates a "submodule" situation that causes confusing
behavior for beginners.
Initializing Git does not automatically track your files. You must explicitly tell Git which files to include in the next save point. This process is called staging. Staged files are placed in a holding area and will be included in your next commit.
The most common approach — stage all files in the current folder and all subfolders:
git add .
The dot (.) is shorthand for "everything here." This is what most beginners and even many
experienced developers use for the majority of commits.
To stage only certain files and leave others unstaged:
git add index.html style.css script.js
Before committing, always check the current state of your working directory:
git status
The output shows everything in color: green files are staged and ready to commit,
red files are modified or new but not yet staged. Running git status frequently —
before staging, before committing, before pushing — is one of the best habits a beginner can build. It keeps you
fully aware of exactly what Git is tracking.
.gitignore file — covered in detail later in this guide
— to permanently exclude sensitive files from being tracked by Git.
A commit is a permanent save point — a complete snapshot of all your staged files at this exact moment in time. Every commit is stored forever in your project history. If something breaks in the future, you can always roll back to any previous commit. This is the core power of version control.
git commit -m "First commit - initial website upload"
The -m flag lets you write a short message describing what this commit contains. The commit message
is for humans — it should clearly describe what changed and why.
The quality of your commit messages directly reflects your professionalism as a developer. Here is the difference in practice:
"fix""update""changes""stuff""aaa""Add contact form to homepage""Fix broken nav link on mobile""Update hero section background""Add Google Fonts and adjust spacing""Initial website upload"When you look back at a project after several months, a well-written commit history reads like a clear changelog — you can see exactly when every feature was added and every bug was fixed. Use present tense: "Add" not "Added." Be specific enough that a stranger reading the message would understand the change without needing to look at the code.
git config --global user.name "Your Name"
git config --global user.email "your.email@example.com"
Git attaches your name and email to every commit. Use the same email address you used to sign up to GitHub so
your commits are linked to your GitHub profile correctly. You only need to do this once per computer.
In Git, a "branch" is a separate timeline of your project. Older versions of Git automatically named the default branch master, but the modern standard — and what GitHub now uses — is main. Renaming ensures that your local branch name matches what GitHub expects, preventing errors when you push.
git branch -M main
The -M flag forces the rename even if another branch with that name already exists. After this
command, your branch is called main and everything aligns with GitHub's default setup.
To make main the automatic default for all future projects on your machine, run this one-time
configuration command:
git config --global init.defaultBranch main
Your Git repository currently exists only on your local computer. You need to link it to the repository you created in Step 1 on GitHub. This link is called a remote — essentially a bookmark that tells Git where to send your code when you push.
git remote add origin https://github.com/YOUR_USERNAME/YOUR_REPO_NAME.git
Replace YOUR_USERNAME with your actual GitHub username and YOUR_REPO_NAME with your
repository name. For example:
git remote add origin https://github.com/johndoe/my-website.git
The word origin is simply a conventional nickname for the remote URL. It's not a special keyword —
it is just the name that virtually every developer in the world uses for their primary remote. Following this
convention makes your workflow compatible with standard tutorials, team projects, and open-source contributions.
Verify that the remote was added correctly by running:
git remote -v
You'll see your GitHub URL listed twice — once for "fetch" (downloading) and once for "push" (uploading). If both URLs match your repository, you are ready for the final push.
This is the final step. "Pushing" sends all your committed code from your local machine up to GitHub, where it is stored and publicly accessible.
git push -u origin main
The -u flag sets origin main as the default upstream. After this first push, you can
simply type git push in the future without specifying the remote name and branch every time.
You'll be prompted to enter your GitHub username and a password. Important: GitHub no longer accepts your account login password for command-line push operations. You must use a Personal Access Token (PAT).
If the push succeeds, you will see output ending with something like "Branch 'main' set up to track remote
branch 'main' from 'origin'." Open your browser and navigate to
https://github.com/YOUR_USERNAME/YOUR_REPO_NAME — you will see all your files listed there. Your
code is now on GitHub!
After the initial upload, keeping your GitHub repository in sync with your latest changes is fast and simple. Every time you edit your website — fixing a typo, adding a new section, redesigning the layout, or updating any content — you follow the same three-step update cycle:
Add all modified and new files to the staging area:
git add .
Create a snapshot of the staged changes with a clear message:
git commit -m "Fix mobile navigation and update footer text"
Upload the new commit to your GitHub repository:
git push
If you have GitHub Pages enabled, your live website will automatically rebuild and show the new changes within one to three minutes of pushing. Simply refresh your browser on the live URL and the update will appear.
Over time, building the habit of committing and pushing regularly — after each meaningful change rather than waiting until a project is entirely finished — makes your workflow far more organized, safer from accidental data loss, and easier to manage as complexity grows.
GitHub Pages is a free static website hosting service built directly into GitHub. It publishes your HTML, CSS, and JavaScript files from your repository as a fully live, publicly accessible website — no server setup, no monthly fees, and no infrastructure to maintain. For beginners, students, and anyone hosting personal projects, it is one of the most useful tools available on the entire internet.
Your site will be live at: https://YOUR_USERNAME.github.io/YOUR_REPO_NAME. This is a real URL you
can share with anyone — a future employer, a client, a professor, or anyone else you want to show your work to.
index.html must be in the root folder. GitHub Pages looks for a file named
exactly index.html at the top level of your repository to serve as the homepage. If your main
HTML file is inside a subfolder such as /src/index.html or /public/index.html,
GitHub Pages will display a 404 error. Either move index.html to the root, or configure the Pages
source folder to point to the correct location.
If you own a custom domain name — like www.yourname.com — you can connect it to your GitHub Pages
site for free. In the Pages settings page, there is a "Custom domain" input field. Enter your domain name and
save. Then log into your domain registrar (GoDaddy, Namecheap, Cloudflare, Google Domains, etc.) and update your
DNS records to point to GitHub's IP addresses. GitHub provides step-by-step instructions for this in their
documentation. Once configured, GitHub also automatically provisions a free HTTPS/SSL certificate through Let's
Encrypt within minutes, so your site will be fully secure without any extra setup.
GitHub Pages is purpose-built for static websites — sites built with HTML, CSS, and JavaScript that run entirely in the browser without needing a server to process requests. It's ideal for portfolios, landing pages, documentation sites, project showcases, and blogs (especially using a static site generator like Jekyll, which GitHub Pages natively supports).
It does not support server-side languages like PHP, Python, Ruby, or Node.js, nor does it support databases. If your project requires a backend API or a database, you will need separate hosting for those components — services like Render, Railway, Fly.io, or Vercel work well alongside GitHub Pages for full-stack projects.
Not every file in your project folder should be uploaded to GitHub. Operating system files, editor configuration
files, compiled build output, package dependency folders, and especially any files containing private
credentials should never be committed. The .gitignore file is how you tell Git to permanently
ignore certain files and folders — they will never appear in git status and will never be staged,
committed, or pushed.
Create a file named exactly .gitignore (with the leading dot, and no file extension) in the root
directory of your project. Inside it, list patterns for everything you want Git to skip:
# Mac OS system files
.DS_Store
# Windows system files
Thumbs.db
desktop.ini
# Node.js — never commit the dependencies folder (it can be hundreds of MB)
node_modules/
# Environment variable files — these often contain API keys and secrets
.env
.env.local
.env.development
.env.production
# Build output directories
dist/
build/
out/
# Code editor configuration folders
.vscode/
.idea/
# Log files
*.log
npm-debug.log*
yarn-debug.log*
Lines beginning with # are comments and are ignored by Git. A trailing slash (/) means
a folder and everything inside it. An asterisk (*) is a wildcard matching any characters. Patterns
are matched from the root of the repository.
.gitignore file tailored to your specific setup. This is much faster than writing one from
scratch and covers edge cases you might not think of. Also: always create your .gitignore file
before your first commit — removing files from Git history after they have been committed and pushed
is significantly more difficult.
Branches are one of Git's most powerful and distinctive features. A branch is an independent, parallel timeline
of your project. You can create a new branch, make any changes you want inside it, and your main
branch remains completely untouched. This lets you experiment, build new features, or try a redesign — all
without any risk to the working version of your project.
The most common beginner use case is a feature branch: create a branch when starting something
new, build it there, and merge it back into main when it works correctly and you are satisfied with
it.
# Create a new branch and switch to it immediately
git checkout -b new-feature
# Now work on your changes... then stage and commit as usual
git add .
git commit -m "Add new portfolio section with project cards"
# When ready, switch back to main
git checkout main
# Merge the feature branch into main
git merge new-feature
# Push the updated main to GitHub
git push
# Optionally delete the branch now that it has been merged
git branch -d new-feature
# List all local branches (the current branch has a * beside it)
git branch
# List all branches, including remote ones on GitHub
git branch -a
As a solo developer on a simple project, you may not feel the need for branches right away — and that is completely fine. However, as projects grow, and especially when collaborating with other developers, branches become absolutely key. They form the backbone of professional workflows like GitHub Flow (create a branch — commit — open a Pull Request — review — merge) that are used at software companies of every size around the world.
Entering your GitHub username and Personal Access Token every single time you push is tedious. SSH (Secure
Shell) key authentication solves this permanently. Once configured, git push authenticates you
automatically in the background — no prompts, no tokens, no typing. This is how most professional developers
interact with GitHub on a daily basis.
SSH uses a matched key pair: a private key that lives only on your computer (never share this) and a public key that you upload to GitHub. When you push, GitHub verifies that the keys match and grants access instantly.
ssh-keygen -t ed25519 -C "your.email@example.com"
Press Enter through all prompts to accept default file locations and skip the passphrase. Two files are
created: id_ed25519 (your private key — never share this) and id_ed25519.pub (your
public key — safe to share).
# Mac or Linux
cat ~/.ssh/id_ed25519.pub
# Windows (Git Bash)
cat ~/.ssh/id_ed25519.pub
Select and copy the entire output — it starts with ssh-ed25519 and ends with your email address.
git remote set-url origin git@github.com:YOUR_USERNAME/YOUR_REPO_NAME.git
From now on, git push will authenticate silently using your SSH key — permanently password-free.
Knowing how to use Git commands is only one part of the picture. Using Git well — with good habits and discipline — is what separates developers who are comfortable in professional environments from those who are not. These six habits are worth building from your very first project.
Don't wait until an entire feature is finished or an entire page is rebuilt before making a commit. Commit after each small, logical unit of work: after adding a navigation bar, after fixing a specific bug, after updating a color. Smaller commits are easier to understand, easier to undo if something goes wrong, and produce a project history that actually tells a coherent story. The test: if you can't summarize what changed in one short sentence, your commit is probably too large — consider splitting it into two commits.
If you work across multiple computers — a laptop at home and a desktop at school, for example — or if you ever
make edits directly on the GitHub website, always run git pull before starting work and before
pushing. This fetches the latest version from GitHub and merges it into your local code. Skipping this step
causes the "rejected — non-fast-forward" error when you try to push because your local history is behind the
remote.
git pull origin main
git status and git diff Before Every Commit
Before running git commit, always take 10 seconds to run git status to see which
files are staged and git diff --staged to see the exact line-by-line changes. This simple habit
prevents accidentally committing debug logs, half-written code, commented-out tests, or — worst of all —
sensitive data. Many experienced developers run git status as an almost unconscious reflex
throughout their workflow.
Create a .gitignore file before your very first commit on every new project. Once a file has been
committed and pushed to GitHub, removing it from the repository history requires advanced techniques (like BFG
Repo Cleaner or git filter-branch) that are messy and error-prone. The effort of setting up
.gitignore upfront takes two minutes and saves significant headaches later, especially when
dealing with API keys, node_modules folders, or IDE configuration files.
A README.md file in the root of your repository is the first thing any visitor sees on your
GitHub project page — it is displayed automatically below your file list. A good README explains what the
project is, what it does, what technologies it uses, how someone would run it locally, and any other relevant
information. GitHub automatically renders Markdown formatting, so you can use headings, bullet points, code
blocks, bold text, and links. Even a brief three-paragraph README transforms a project from looking like a
random pile of files to a professional, well-documented piece of work.
API keys, access tokens, database passwords, and private configuration values should never appear in
a Git commit — not even in a private repository. If you accidentally commit a secret and push it, consider it
compromised: rotate (replace) it immediately at the service that issued it. Use environment variables and
.env files (excluded via .gitignore) to store credentials, and reference them in
your code through process.env.YOUR_KEY rather than hardcoding values directly in your source
files.
Here are the most frequent errors beginners run into when working with Git and GitHub, along with clear explanations and exact fixes for each:
git init
first before any other Git commands.
git remote remove origin
git remote add origin https://github.com/YOUR_USERNAME/YOUR_REPO_NAME.git
git pull origin main --rebase
git push
<<<<<<< HEAD, =======, and
>>>>>>>. Manually edit the file to keep the correct version and remove all
conflict markers. Then:
git add .
git commit -m "Resolve merge conflict in style.css"
.gitignore before the commit.git reset HEAD~1, add the file to .gitignore, then recommit. If you have already
pushed, assume the credential is compromised — immediately rotate (invalidate and replace) the API key
or password at the issuing service, then use the BFG Repo Cleaner tool to scrub the file from Git history. Do
not rely on simply deleting the file in a new commit — the secret remains visible in the commit history.
Every Git command covered in this guide, organized in a single reference table:
| Command | What It Does |
|---|---|
git --version |
Check that Git is installed and view the version |
git config --global user.name "Name" |
Set your display name attached to all commits |
git config --global user.email "email" |
Set your email address attached to all commits |
git config --global init.defaultBranch main |
Set "main" as the default branch for new repos |
git init |
Initialize a new Git repository in the current folder |
git status |
Show staged, modified, and untracked files |
git add . |
Stage all changes and new files in the current folder |
git add filename |
Stage a single specific file |
git diff |
Show unstaged line-by-line changes |
git diff --staged |
Show staged changes that are ready to commit |
git commit -m "message" |
Save staged changes as a commit with a message |
git branch -M main |
Rename the current branch to "main" |
git remote add origin URL |
Link local repository to a GitHub remote |
git remote -v |
View all remote connections and their URLs |
git remote set-url origin URL |
Change the remote URL (e.g. switch to SSH) |
git push -u origin main |
Push and set the default upstream — first push only |
git push |
Push new commits to GitHub after initial setup |
git pull |
Fetch and merge the latest changes from GitHub |
git pull origin main --rebase |
Pull and rebase to keep history linear |
git log |
View the full commit history with details |
git log --oneline |
View commit history in compact one-line format |
git checkout -b branch-name |
Create and immediately switch to a new branch |
git checkout main |
Switch back to the main branch |
git merge branch-name |
Merge a branch into the currently active branch |
git branch -d branch-name |
Delete a branch after it has been merged |
git reset HEAD~1 |
Undo the last commit but keep the file changes |
git clone URL |
Download an existing GitHub repository to your computer |
# 1. Navigate to your project folder
cd your-project-folder
# 2. Initialize Git
git init
# 3. Stage all files
git add .
# 4. Create your first commit
git commit -m "Initial website upload"
# 5. Rename branch to main
git branch -M main
# 6. Link to your GitHub repository (replace with your actual URL)
git remote add origin https://github.com/YOUR_USERNAME/YOUR_REPO_NAME.git
# 7. Push to GitHub for the first time
git push -u origin main
After the initial setup, this is everything you need every time you update your site:
git add .
git commit -m "Describe what you changed"
git push
Uploading your website to GitHub might feel unfamiliar the first time, but the process becomes genuinely quick and effortless after a couple of repetitions. The initial setup — initializing Git, staging files, making your first commit, linking to GitHub, and pushing — is the steepest part of the learning curve. Once that is done, maintaining your repository is just three commands repeated as many times as you need.
After your first push, updating your live site is simply: git add .,
git commit -m "message", and git push. That three-command loop is something
professional developers run dozens of times per day on projects of every scale. By learning it now, on your
own small projects, you are building the exact same muscle memory and habits they have.
GitHub Pages extends the value of GitHub even further by giving you free, instant, zero-maintenance hosting for any static website. For portfolios, school assignments, personal experiments, and client prototypes, it is hard to beat — no server to configure, no invoice to pay each month, no downtime to worry about. The live URL it provides is real, shareable, and professional enough to send to any employer or client.
Beyond the technical workflow, using GitHub consistently builds something even more valuable: your developer reputation. Every repository you publish, every meaningful commit message you write, every project you complete and push — all of it accumulates into a public record of your growth and skill as a developer. This record is often more persuasive to technical employers and clients than a resume or a cover letter ever could be, because it shows real work rather than just claims about work.
The best way to internalize Git is simply to use it every day on real projects. Start something new today, make regular commits, push to GitHub, and let the repetition turn these commands into instincts. Within a few weeks, version control will feel as natural as saving a document — and you will look back wondering how you ever wrote code without it.
Happy coding, and welcome to GitHub! ’xa—