// GENERAL

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

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 πŸ