You wrote code on your computer. Now you want it on GitHub — backed up, shareable, and version tracked.
This tutorial shows you exactly how to do that from the terminal.
Make sure you have:
- Git installed → git --version (should show a version number)
- A GitHub account
- A project folder on your computer
cd your_project_folder
This tells Git to start tracking your project.
git init
You'll see: Initialized empty Git repository
Stage all files so Git knows what to include:
git add .
The . means "everything in this folder".
To check what's staged:
git status
A commit is like saving a snapshot of your code.
git commit -m "first commit"
Write a short message that describes what you did. This message shows in your GitHub history.
my-project)GitHub shows you a URL like:
https://github.com/yourusername/my-project.git
Copy it.
git remote add origin https://github.com/yourusername/my-project.git
git branch -M main
git push -u origin main
Go to your GitHub repo — your files are now there. ✅
git init # Start tracking
git add . # Stage all files
git commit -m "message" # Save snapshot
git remote add origin <url> # Connect to GitHub
git push -u origin main # Upload code
error: src refspec main does not match any
→ You haven't committed yet. Run git add . and git commit first.
remote: Repository not found
→ Wrong URL. Check the GitHub repo URL and run git remote set-url origin <correct-url>
Username/password prompt
→ GitHub no longer accepts passwords. Use a Personal Access Token or switch to SSH.