Whether you’re building a portfolio, sharing a side project, or collaborating with a team, GitHub makes it easy to host and manage your code online. In this guide, you’ll learn how to host your project on GitHub, from creating a repository to pushing your code.
📁 Prerequisites
Make sure you have the following:
- A GitHub account
- Git installed on your computer (run
git --version
to check)
🛠️ Step 1: Create a GitHub Repository
- Go to https://github.com
- Click + in the top right → New repository
- Enter repository details:
- Name: e.g.,
my-portfolio
- Description: (Optional)
- Choose Public or Private
- Name: e.g.,
- Click Create repository
💻 Step 2: Initialize Git Locally (If You Haven’t)
If your project is not yet a Git repository, open your terminal and navigate to your project folder:
cd path/to/your-project
git init
📥 Step 3: Add and Commit Files
git add .
git commit -m "Initial commit"
This stages and commits all your files.
🌐 Step 4: Connect to GitHub
Copy the GitHub repository URL (HTTPS or SSH) and run:
git remote add origin https://github.com/your-username/your-repo-name.git
Then push your code:
git push -u origin main
If your branch is called
master
, usemaster
instead ofmain
.
🧪 Step 5 (Optional): Set Up GitHub Pages (for Hosting Static Websites)
- Go to your repository on GitHub
- Click Settings
- Scroll to Pages
- Under Source, choose a branch (e.g.,
main
) and folder (/root
or/docs
) - Click Save
Your website will be live at:
https://your-username.github.io/your-repo-name/
✅ Summary of Commands
git init
git add .
git commit -m "Initial commit"
git remote add origin <repo-URL>
git push -u origin main
🏁 Conclusion
Hosting your project on GitHub not only backs up your code but also makes it easy to collaborate, manage issues, and showcase your work. GitHub Pages even lets you turn your project into a live website in minutes.