Connect Your Project to GitHub
GitHub is where your code lives, your changes are tracked, and your deployments become repeatable. If you're building Node.js apps, Astro sites, or any modern web project, GitHub is the default control center.
This guide shows you how to:
- Connect a project to a GitHub repository
- Push changes safely using SSH or HTTPS

Before you start¶
You need:
- A GitHub account and a repository (empty or existing)
- Git installed on your machine or server
- Terminal access (local PC, VPS, or server shell)
Quick check:
Set your Git identity (do this once):
Choose how you want to authenticate¶
You have 3 good options:
- SSH (recommended): fast, secure, no tokens in prompts
- HTTPS + Personal Access Token (PAT): works everywhere, good fallback
- GitHub CLI: guided setup that can manage credentials for you
Pick one and stick to it.
Option A: Connect using SSH (recommended)¶
Step 1: Create an SSH key (if you do not already have one)¶
Check existing keys:
Generate a new key (Ed25519):
When asked for a file path, press Enter to accept default.
Add a passphrase if the machine is shared or security-sensitive.
Step 2: Start the SSH agent and add your key¶
Step 3: Add your public key to GitHub¶
Print the public key and copy it:
In GitHub:
- Profile icon → Settings
- SSH and GPG keys
- New SSH key
- Paste the key and save
Step 4: Test the connection¶
Expected outcome: GitHub confirms authentication. (No shell access is normal.)
Option B: Connect using HTTPS + Personal Access Token (PAT)¶
If Git asks for a password during Git operations, you must use a Personal Access Token.
Step 1: Create a token on GitHub¶
Create a PAT (fine-grained if possible) and store it in a password manager.
Step 2: Use the token when prompted¶
When you run git push over HTTPS:
- Username: your GitHub username
- Password: paste your token
Tip: consider a credential helper so you do not retype the token every time.
Option C: Connect using GitHub CLI (fastest setup)¶
Install GitHub CLI (gh) and run:
Optional, to configure Git to use GitHub CLI credentials:
Connect your project to a GitHub repository¶
Scenario 1: Clone an existing repo¶
SSH:
HTTPS:
Scenario 2: Push an existing project folder to GitHub¶
From inside your project folder:
Add the remote.
SSH:
HTTPS:
Set your default branch to main and push:
Verify your remotes anytime:
The push workflow you should actually use (daily routine)¶
1) Check what changed¶
2) Stage changes¶
Stage everything:
Or stage specific files:
3) Commit with a clear message¶
4) Pull first (avoids push rejection)¶
If you work on multiple machines or with a team:
5) Push to GitHub¶
If you are on a new branch:
Node.js and Astro: use a solid .gitignore¶
Never commit build artifacts and secrets. Here’s a safe baseline:
# Dependencies
node_modules/
# Build outputs
dist/
.build/
.out/
.astro/
.next/
.nuxt/
.svelte-kit/
# Logs
npm-debug.log*
yarn-debug.log*
pnpm-debug.log*
# Env and secrets
.env
.env.*
!.env.example
# OS / editor junk
.DS_Store
.vscode/
.idea/
Tip: create an .env.example with placeholder values so teammates know what to set.
Troubleshooting¶
“Permission denied (publickey)”¶
This is SSH auth failing.
- Confirm the key is loaded:
- Confirm your GitHub remote is SSH:
- Re-test:
“Support for password authentication was removed”¶
You are using HTTPS and tried to use your GitHub password.
Fix: use a Personal Access Token instead of password, or switch your remote to SSH.
“failed to push some refs”¶
Usually you are behind the remote branch.
Fix:
“fatal: remote origin already exists”¶
You already added a remote.
Fix:
git remote set-url origin git@github.com:OWNER/REPO.git
# or
git remote set-url origin https://github.com/OWNER/REPO.git
Summary¶
- SSH is the cleanest long-term setup for pushing code to GitHub.
- HTTPS + PAT is the best fallback if SSH is blocked.
- GitHub CLI is the easiest guided setup.
- Daily routine: status → add → commit → pull --rebase → push