CurriculumGitHub FundamentalsCreating a GitHub Repository
Lesson 2 of 825%
Intermediate6 min+60 XP

Creating a GitHub Repository

Creating a repository on GitHub is the starting point for sharing and collaborating on code. You can start fresh on GitHub and clone down, or connect an existing local project to a new GitHub repo.

01.Two Approaches to Creating a Repo

Approach A (existing local project): Create an empty repo on GitHub with no files, copy the remote URL, add it as origin in your local project, push. Approach B (starting fresh): Create the repo on GitHub with a README and .gitignore, then clone it to your machine and start coding. Both are valid — pick based on your situation.

Distributed Architecture
💻
Your Local
push / pull
☁️
GitHub (Remote)
push / pull
💻
Teammate's Local

02.Key Settings When Creating

Public: visible to everyone — great for open source and required for free GitHub Pages hosting. Private: only you and collaborators can see it. README.md: a markdown file describing your project (always add this). .gitignore: tells Git to ignore build outputs, node_modules, .env files, and OS junk. LICENSE: essential for open source — without it, no one can legally use your code.

my-project/
📁my-project/
📁.git/← Git database
📄config
📄HEAD
📁objects/
📁refs/
📄README.md
📁src/

Commands

commands — click to reveal output
$
# github.com → click "+" → "New repository"
Create via the GitHub web UI
$
git remote add origin https://github.com/user/new-repo.git
Connect your local repo to the new GitHub repo
$
git branch -M main
Rename master to main if needed
$
git push -u origin main
Push your code and set up tracking
▼ show output
$
gh repo create my-project --public --source=. --push
Create GitHub repo, link, and push — all in one CLI command
KNOWLEDGE CHECK

What does a .gitignore file do?

Rate this lesson:
PreviousNext Lesson