Connecting to GitHub
To push code from your computer to GitHub securely, we use SSH Keys. Think of this as a special digital handshake that proves who you are without typing your password every time.
Why SSH?
Secure, encrypted, and convenient. Once set up, you just `git push` and it works.
Step 1: Generate SSH Key
# 1. Open Git Bash and run:
ssh-keygen -t ed25519 -C "your.email@example.com"
# 2. Press Enter 3 times (accept default file location and empty passphrase)
# 3. Start the ssh-agent in the background
eval "$(ssh-agent -s)"
# 4. Add your SSH private key to the ssh-agent
ssh-add ~/.ssh/id_ed25519
# 5. Copy the public key to clipboard
clip < ~/.ssh/id_ed25519.pub
Step 2: Add Key to GitHub
Now that you have copied your public key, let's give it to GitHub.
- Go to GitHub Settings > SSH and GPG keys.
- Click the green New SSH key button.
- Title: Give it a name like "My Laptop".
- Key: Paste the key you copied in the previous step.It should start with
ssh-ed25519... - Click Add SSH key.
Step 3: Create Repo & Push
Time to put your code on the internet!
1. Create Empty Repo
- Click the + icon in top-right of GitHub.
- Select New repository.
- Name it
my-first-repo. - Leave it Public.
- DO NOT check "Initialize with README".
- Click Create repository.
2. Push Local Code
Run these commands in your project folder:
# Link local repo to GitHub
git remote add origin git@github.com:YOUR_USERNAME/my-first-repo.git
# Rename branch to main (if needed)
git branch -M main
# Push code!
git push -u origin main
Success!
Refresh your GitHub page. You should see your files there. You have successfully connected your computer to the cloud!