Skip to content
ajdevhub

// GENERAL

How to Create a New GitHub Repo and Push a Local Project

When you start a new project locally (Java, DSA notes, website, etc.), the next step is usually to push it into GitHub. This guide explains the complete workflow.

2026-01-18

How to Create a New GitHub Repo and Push a Local Project 🚀

When you start a new project locally (Java, DSA notes, website, etc.), the next step is usually to push it into GitHub. This guide explains the complete workflow to:

✅ Create a new GitHub repository
✅ Initialize Git in your local project
✅ Commit your code
✅ Push it to GitHub

This is a reusable step-by-step process you can follow for any future project.


Prerequisites

Before starting, make sure you have:

  • A GitHub account
  • Git installed on your system

Check Git installation:

git --version

Step 1: Create a New Repository on GitHub

  1. Open GitHub and click ”+” → New repository
  2. Enter a repository name
    Example: JavaFoundry
  3. Choose repo visibility:
    • ✅ Public (recommended for portfolio)
    • 🔒 Private (if needed)
  4. Important: Do NOT check:
    • “Add a README”
    • “Add .gitignore”
    • “Add license”

(We will create them locally.)

  1. Click Create repository

GitHub will show the repo URL like:

  • HTTPS: https://github.com/<username>/<repo>.git
  • SSH: git@github.com:<username>/<repo>.git

Step 2: Open Terminal in Your Local Project Folder

Navigate into your project folder:

cd path/to/your/project

Verify files:

ls

Step 3: Initialize Git in Your Local Folder

Run:

git init

Now your folder becomes a Git repository.


A .gitignore tells Git what NOT to push to GitHub.

Create .gitignore:

touch .gitignore

For Java + IntelliJ projects, add:

# IntelliJ IDEA
.idea/
*.iml

# Java build output
out/
target/
*.class

# OS files
.DS_Store
Thumbs.db

Step 5: Stage Your Code

Stage everything:

git add .

Check status:

git status

Step 6: Commit Your Changes

Commit with a meaningful message:

git commit -m "Initial commit"

Add the GitHub remote:

✅ Using HTTPS

git remote add origin https://github.com/<username>/<repo>.git

Verify remote:

git remote -v

Step 8: Push Your Code to GitHub

Rename branch to main (GitHub standard):

git branch -M main

Push code:

git push -u origin main

✅ Done — your local project is now available on GitHub.


Step 9: Verify on GitHub

Go to your repo page and refresh. You should see:

  • all your files
  • latest commit message
  • branch main

Common Errors and Fixes

1) ❌ remote origin already exists

Fix:

git remote remove origin
git remote add origin https://github.com/<username>/<repo>.git

2) ❌ Authentication Failed (HTTPS)

GitHub no longer allows password authentication for git pushes.

✅ Fix options:

  • Use Personal Access Token (PAT) as password
  • OR use SSH
  • OR use GitHub Desktop (easy UI)

Recommended Workflow for Future Updates

Whenever you make changes:

git add .
git commit -m "Updated notes: Constructors + GC"
git push

Bonus: Best Repo Structure for Learning Projects

If you’re building a learning repo like JavaFoundry:

JavaFoundry/
├── src/
├── notes/
│   ├── constructors.md
│   ├── methods.md
│   └── memory-management-gc.md
├── diagrams/
│   └── *.puml
├── README.md
└── .gitignore

This makes your repo clean and scalable.


Summary

✅ Create repo on GitHub
✅ git init locally
✅ git add .
✅ git commit -m "..."
✅ git remote add origin <url>
✅ git push -u origin main


← All Blogs Home 🏠
general