DEV Community

Lagat Josiah
Lagat Josiah

Posted on

Step-by-Step Guide to Push a New Project to GitHub

πŸš€ Step-by-Step Guide to Push a New Project to GitHub


🧰 Prerequisites

Before you start, make sure you have:


πŸͺ„ STEP 1 β€” Initialize Git in Your Project

Go inside your project folder:

cd ~/path/to/my-project
Enter fullscreen mode Exit fullscreen mode

Initialize a new Git repository:

git init
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

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"
Enter fullscreen mode Exit fullscreen mode

Check your config:

git config --list
Enter fullscreen mode Exit fullscreen mode

🧱 STEP 4 β€” Add and Commit Your Files

Tell Git to track your files:

git add .
Enter fullscreen mode Exit fullscreen mode

Then make your first commit:

git commit -m "Initial commit"
Enter fullscreen mode Exit fullscreen mode

☁️ STEP 5 β€” Create a Repository on GitHub

  1. Go to GitHub β†’ New Repository
  2. Choose a name (e.g., my-project)
  3. DO NOT initialize with a README, .gitignore, or license (since your local repo already has one)
  4. 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
Enter fullscreen mode Exit fullscreen mode

🌍 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
Enter fullscreen mode Exit fullscreen mode

Check that it was added correctly:

git remote -v
Enter fullscreen mode Exit fullscreen mode

πŸͺœ 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
Enter fullscreen mode Exit fullscreen mode

🚒 STEP 8 β€” Push Your Code to GitHub

Push your local branch to GitHub for the first time:

git push -u origin main
Enter fullscreen mode Exit fullscreen mode

If you kept master:

git push -u origin master
Enter fullscreen mode Exit fullscreen mode

-u sets the remote tracking branch, so next time you can just use git 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"
Enter fullscreen mode Exit fullscreen mode

Press Enter through defaults (it saves to ~/.ssh/id_ed25519).

2. Add the SSH key to your GitHub account:

cat ~/.ssh/id_ed25519.pub
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

πŸ”„ 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
Enter fullscreen mode Exit fullscreen mode

Top comments (0)