How to Set Up a Project on GitHub
A step-by-step guide to creating your first GitHub repository, connecting it to your local code, and establishing good habits from the start.
Before you start
You need:
- A GitHub account (free at github.com)
- Git installed on your computer (
git --versionshould show a version number) - A terminal (Terminal on Mac, Git Bash on Windows, or the terminal in VS Code)
If Git isn’t installed, download it from git-scm.com .
Method 1: Start on GitHub (recommended for beginners)
This is the cleanest way to start a new project.
Step 1: Create the repository on GitHub
- Go to github.com and sign in
- Click the + icon in the top right → New repository
- Fill in:
- Repository name:
my-project(lowercase, hyphens for spaces) - Description: Optional but helpful
- Public or Private: Your choice
- Add a README file: ✓ Check this
- Add .gitignore: Select your language (Node, Python, etc.)
- Choose a license: MIT is common for open source; skip if private
- Repository name:
- Click Create repository
You now have a repository on GitHub with a README, .gitignore, and optionally a license.
Step 2: Clone to your computer
On your new repository page, click the green Code button and copy the URL.
In your terminal:
# Navigate to where you want the project
cd ~/code # or wherever you keep projects
# Clone the repository
git clone https://github.com/YOUR-USERNAME/my-project.git
# Enter the project folder
cd my-projectYou now have a local copy connected to GitHub.
Step 3: Add your files
Put your project files in this folder. If you’re starting fresh:
# Create some files
touch index.html
touch styles.css
touch app.jsOr copy existing files into the folder.
Step 4: Stage, commit, push
# See what's new or changed
git status
# Stage all changes
git add .
# Commit with a message
git commit -m "Add initial project files"
# Push to GitHub
git pushDone. Your files are now on GitHub.
Method 2: Start locally, connect to GitHub
Use this if you already have code on your computer.
Step 1: Initialize Git in your folder
# Navigate to your project folder
cd ~/code/my-existing-project
# Initialize Git
git init
# Stage all files
git add .
# Make your first commit
git commit -m "Initial commit"Step 2: Create an empty repo on GitHub
- Go to GitHub → New repository
- Name it the same as your folder
- Don’t add README, .gitignore, or license (you already have files)
- Click Create repository
GitHub shows instructions. Follow the “push an existing repository” section.
Step 3: Connect and push
# Connect your local repo to GitHub
git remote add origin https://github.com/YOUR-USERNAME/my-existing-project.git
# Rename your branch to main (if needed)
git branch -M main
# Push your code
git push -u origin mainThe -u flag sets up tracking so future pushes just need git push.
Setting up .gitignore
The .gitignore file tells Git which files to ignore—files that should never be committed.
Always ignore:
# Dependencies
node_modules/
.venv/
__pycache__/
# Environment/secrets
.env
.env.local
*.key
*.pem
# System files
.DS_Store
Thumbs.db
# Build outputs
dist/
build/
.next/
out/
# IDE settings (optional)
.vscode/
.idea/If you didn’t add a .gitignore when creating the repo, create one now:
# Create .gitignore
touch .gitignore
# Edit it and add the patterns aboveThen commit it:
git add .gitignore
git commit -m "Add .gitignore"
git pushGitHub provides templates for every language: github.com/github/gitignore
Writing a good README
The README.md is the first thing people see. At minimum, include:
# Project Name
One-sentence description of what this does.
## Getting Started
```bash
# Install dependencies
npm install
# Run the development server
npm run devWhat it does
- Feature 1
- Feature 2
- Feature 3
License
MIT
For a side project, that's enough. Expand as the project grows.
## The daily workflow
Once set up, your routine is:
```bash
# Start of session: get latest changes
git pull
# Make changes to files...
# End of session: save and upload
git add .
git commit -m "Describe what changed"
git pushCommit often. Small, frequent commits are better than one massive commit at the end of the day.
Good commit messages
Bad:
- “Update”
- “Fixed stuff”
- “asdfgh”
- “WIP”
Good:
- “Add user login form”
- “Fix redirect after password reset”
- “Remove unused dependencies”
- “Update README with setup instructions”
The message should complete the sentence: “This commit will…”
Using branches (even solo)
Even when working alone, branches protect you:
# Create a branch for your feature
git checkout -b feature/add-dark-mode
# Make changes, commit as usual
git add .
git commit -m "Add dark mode toggle"
git push -u origin feature/add-dark-mode
# When done, merge into main
git checkout main
git merge feature/add-dark-mode
git push
# Delete the feature branch
git branch -d feature/add-dark-modeIf your feature turns out badly, you can abandon the branch. Main stays clean.
When things go wrong
“I committed something I shouldn’t have”
# Undo the last commit, keep changes staged
git reset --soft HEAD~1“I need to undo changes to a file”
# Discard changes in working directory
git checkout -- filename.js“I committed to main when I meant to use a branch”
# Create a branch from current state
git branch feature/my-work
# Reset main to before your commits
git reset --hard HEAD~1
# Switch to your new branch
git checkout feature/my-work“I pushed secrets by accident”
- Immediately revoke/rotate the exposed credentials
- Remove from history (complex—look up
git filter-branchor BFG Repo-Cleaner) - Force push the cleaned history
- Consider the secret permanently compromised
Prevention is better: always use .gitignore and environment variables.
VS Code integration
If you use VS Code, Git is built in:
- Source Control panel (Ctrl/Cmd + Shift + G): See changes, stage, commit
- GitLens extension: Rich history, blame annotations, visual diffs
- Terminal: All Git commands work here too
You can do everything through the GUI or the terminal—whatever feels right.
Checklist for new projects
- Repository created on GitHub
- Cloned locally
- .gitignore added with appropriate patterns
- README.md with basic information
- First commit pushed
- (Optional) LICENSE file added
- (Optional) Branch protection on main
Further reading
- Git vs GitHub : Understanding the difference
- What is Git? : The full story of version control
- What is a Git branch? : Working with branches
- How to collaborate on GitHub : Working with others
- What is an environment variable? : Keeping secrets out of your repo
Frequently asked questions