π Step-by-Step Guide to Push a New Project to GitHub
π§° Prerequisites
Before you start, make sure you have:
- Git installed
- A GitHub account
- Your project directory ready (e.g.,
my-project)
πͺ STEP 1 β Initialize Git in Your Project
Go inside your project folder:
cd ~/path/to/my-project
Initialize a new Git repository:
git init
This creates a hidden .git folder that tracks changes in your project.
π§© STEP 2 β (Optional) Create a .gitignore File
You can tell Git which files/folders not to track (like virtual environments, credentials, build files, etc.):
Example .gitignore:
__pycache__/
.env
node_modules/
venv/
*.log
Add it to your project root.
π€ STEP 3 β Set Your Git Identity
Set your global username and email (Git needs this for commits):
git config --global user.name "Your Name"
git config --global user.email "you@example.com"
Check your config:
git config --list
π§± STEP 4 β Add and Commit Your Files
Tell Git to track your files:
git add .
Then make your first commit:
git commit -m "Initial commit"
βοΈ STEP 5 β Create a Repository on GitHub
- Go to GitHub β New Repository
- Choose a name (e.g.,
my-project) - DO NOT initialize with a README, .gitignore, or license (since your local repo already has one)
- Click Create repository
Youβll now see a page with instructions like:
git remote add origin https://github.com/username/my-project.git
git branch -M main
git push -u origin main
π STEP 6 β Add the Remote (Connect Local β GitHub)
Copy the remote URL from GitHub and add it:
git remote add origin https://github.com/username/my-project.git
Check that it was added correctly:
git remote -v
πͺ STEP 7 β Rename Default Branch (Optional but Recommended)
GitHub uses main as the default branch.
If your repo uses master, rename it:
git branch -M main
π’ STEP 8 β Push Your Code to GitHub
Push your local branch to GitHub for the first time:
git push -u origin main
If you kept master:
git push -u origin master
-usets the remote tracking branch, so next time you can just usegit push.
π STEP 9 β (Optional) Set Up SSH Authentication
So you donβt have to enter your username/password every time.
1. Generate a new SSH key:
ssh-keygen -t ed25519 -C "you@example.com"
Press Enter through defaults (it saves to ~/.ssh/id_ed25519).
2. Add the SSH key to your GitHub account:
cat ~/.ssh/id_ed25519.pub
Copy the output β Go to GitHub β Settings β SSH and GPG keys β New SSH key β Paste and save.
3. Test it:
ssh -T git@github.com
If successful, youβll see:
Hi username! Youβve successfully authenticated.
Then you can change your remote to SSH:
git remote set-url origin git@github.com:username/my-project.git
π STEP 10 β Common Commands for Future Updates
| Task | Command |
|---|---|
| Check file changes | git status |
| Stage all changes | git add . |
| Commit changes | git commit -m "Your message" |
| Push changes to GitHub | git push |
| Pull latest changes | git pull |
| View commit history | git log --oneline |
β Summary
Hereβs a quick recap of the minimal commands to push a new project:
cd my-project
git init
git add .
git commit -m "Initial commit"
git branch -M main
git remote add origin https://github.com/username/my-project.git
git push -u origin main
Top comments (0)