You’ve created a project on your local machine using Git — great! But now it’s time to share it with the world (or your team) by pushing it to GitHub. Whether you’re collaborating on a team or showcasing your work, GitHub is the go-to platform for hosting Git repositories in the cloud.
In this guide, we’ll walk through how to push a local Git repository to GitHub step by step.
Prerequisites
Before we start, make sure you have the following:
✅ A GitHub account
✅ Git installed on your machine (check with git --version
)
✅ A local Git repository (initialize with git init
if needed)
Step 1: Create a New Repository on GitHub
- Go to github.com and log in.
- Click the + icon in the top right corner and select “New repository”.
- Enter a repository name and description.
- Choose public or private visibility.
- Do not initialize the repo with a README (since your local repo already exists).
- Click “Create repository”.
GitHub will now show you a set of instructions — keep this page open.
Step 2: Connect Your Local Repository to GitHub
Navigate to your local project folder:
cd /path/to/your/project
If you haven’t already, initialize it as a Git repo:
git init
Now, add the GitHub repository as a remote named origin
:
git remote add origin https://github.com/your-username/your-repo-name.git
🔁 Replace
your-username
andyour-repo-name
with your actual GitHub username and repository name.
Step 3: Commit Your Changes Locally
If you haven’t committed any changes yet:
git add .
git commit -m "Initial commit"
This stages and commits all your project files.
Step 4: Push to GitHub
Now push your local commits to GitHub:
git push -u origin main
🔀 If your default branch is named
master
, use that instead:git push -u origin master
The -u
flag sets the upstream, so future pushes can be done with just git push
.
Step 5: Verify Your Repository on GitHub
Visit your GitHub repository page, and you should now see all your files and commit history.
Common Issues & Fixes
❌ Error: fatal: remote origin already exists
You’ve likely already added a remote. Check with:
git remote -v
To change the remote URL:
git remote set-url origin https://github.com/your-username/your-repo-name.git
🔐 Authentication Issues
If you’re prompted for a username/password, GitHub now requires token-based authentication. You can either:
- Use SSH instead of HTTPS
Example:git remote set-url origin [email protected]:your-username/your-repo-name.git
- Or use a personal access token in place of your password.
Final Thoughts
Pushing your local Git repository to GitHub is an essential part of modern software development. Whether you’re collaborating on a team or simply backing up your work, this process helps keep your code safe, accessible, and shareable.
Summary Checklist
✅ Create a new GitHub repo
✅ Initialize Git locally
✅ Add the GitHub repo as a remote
✅ Commit your code
✅ Push to GitHub