Skip to content

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

Email setup

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:

git --version

Set your Git identity (do this once):

git config --global user.name "Your Name"
git config --global user.email "you@example.com"

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.

Step 1: Create an SSH key (if you do not already have one)

Check existing keys:

ls -la ~/.ssh

Generate a new key (Ed25519):

ssh-keygen -t ed25519 -C "you@example.com"

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

eval "$(ssh-agent -s)"
ssh-add ~/.ssh/id_ed25519

Step 3: Add your public key to GitHub

Print the public key and copy it:

cat ~/.ssh/id_ed25519.pub

In GitHub:

  1. Profile icon → Settings
  2. SSH and GPG keys
  3. New SSH key
  4. Paste the key and save

Step 4: Test the connection

ssh -T git@github.com

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:

gh auth login

Optional, to configure Git to use GitHub CLI credentials:

gh auth setup-git

Connect your project to a GitHub repository

Scenario 1: Clone an existing repo

SSH:

git clone git@github.com:OWNER/REPO.git
cd REPO

HTTPS:

git clone https://github.com/OWNER/REPO.git
cd REPO

Scenario 2: Push an existing project folder to GitHub

From inside your project folder:

git init
git add .
git commit -m "Initial commit"

Add the remote.

SSH:

git remote add origin git@github.com:OWNER/REPO.git

HTTPS:

git remote add origin https://github.com/OWNER/REPO.git

Set your default branch to main and push:

git branch -M main
git push -u origin main

Verify your remotes anytime:

git remote -v

The push workflow you should actually use (daily routine)

1) Check what changed

git status

2) Stage changes

Stage everything:

git add .

Or stage specific files:

git add path/to/file

3) Commit with a clear message

git commit -m "Fix navbar spacing on mobile"

4) Pull first (avoids push rejection)

If you work on multiple machines or with a team:

git pull --rebase

5) Push to GitHub

git push

If you are on a new branch:

git push -u origin your-branch-name

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:
ssh-add -l
  • Confirm your GitHub remote is SSH:
git remote -v
  • Re-test:
ssh -T git@github.com

“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:

git pull --rebase
git push

“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