Falytom logoFALYTOM
Games
ToolsUI ComponentsServicesProductsAbout
menu
  1. Home
  2. /Web Development
  3. /Github
  4. /Connecting To Github
Your Progress0%
0 of 20 completed

Git & Github Topics

Getting Started

  • What is Git?
  • What is GitHub?
  • Installing & Configuring Git
  • Your First Git Repository

Core Git Concepts

  • Understanding Commits & History
  • Working with Branches
  • Merging Branches
  • The Staging Area
  • Undoing Changes

Working with GitHub

  • Connecting to GitHub
  • Pushing & Pulling Code
  • Cloning Repositories
  • GitHub README & Documentation

Collaboration Workflows

  • Forking & Pull Requests
  • Code Review Basics
  • Handling Merge Conflicts
  • Issues & Project Management

Best Practices & Workflows

  • Git Workflow Best Practices
  • Working with .gitignore
  • Common Git Problems & Solutions

Connecting to GitHub

Set up remote repositories and authenticate with GitHub

So far, you've been working with Git entirely on your local machine. Now it's time to connect to GitHub and start collaborating! In this lesson, you'll learn what remote repositories are, how to link your local Git repositories to GitHub, set up authentication (SSH keys or HTTPS), and understand the relationship between local and remote repositories. By the end, you'll be ready to share your code with the world and collaborate with other developers.

What Are Remote Repositories?

A remote repository is a Git repository hosted on a server somewhere—typically GitHub, GitLab, or Bitbucket. It's essentially a copy of your repository that lives in the cloud.

Local vs Remote

Local Repository:

  • Lives on your computer
  • Only you can access it
  • Where you do your actual work
  • Fast—no internet required

Remote Repository:

  • Lives on a server (like GitHub)
  • Others can access it (if you give permission)
  • Acts as a backup and collaboration hub
  • Requires internet connection

Why Use Remote Repositories?

  • Backup: Your code is safe even if your computer breaks
  • Collaboration: Multiple people can work on the same project
  • Sharing: Show your work to others or contribute to open source
  • Deployment: Many services deploy directly from GitHub
  • Portfolio: Your GitHub profile showcases your projects
  • Access anywhere: Work from different computers

☁️ Think of It Like Cloud Storage

Remote repositories are similar to Google Drive or Dropbox for your code, but with superpowers—you can sync changes, track who made what changes, review code, and more!

Before You Begin

Make sure you have:

  1. A GitHub account: If you don't have one, create it at github.com
  2. Git installed and configured: With your name and email (we did this in lesson 3)
  3. A local repository: We'll use one you created in earlier lessons
BASH
# Verify Git is configured
git config --global user.name
git config --global user.email

# Should show your name and email

Creating a Repository on GitHub

Let's create a repository on GitHub to connect to your local repository.

Step 1: Go to GitHub

Navigate to github.com and log in.

Step 2: Create New Repository

  1. Click the "+" icon in the top-right corner
  2. Select "New repository"

Step 3: Configure Repository

Fill in the details:

  • Repository name: Use the same name as your local repository (e.g., my-first-repo)
  • Description: Optional but helpful (e.g., "My first Git repository")
  • Public or Private:
    • Public: Anyone can see it (good for open source, portfolios)
    • Private: Only you and collaborators you invite can see it
  • Initialize repository: Leave all checkboxes UNCHECKED (no README, no .gitignore, no license)

Important: Don't initialize the repository with any files! We're connecting an existing local repository, so we want GitHub to create an empty repository.

Step 4: Create Repository

Click "Create repository" button. You'll see a page with setup instructions—we'll use these next!

Authentication Methods

To connect to GitHub, you need to authenticate. There are two main methods:

Method 1: HTTPS (Simpler, Recommended for Beginners)

Pros:

  • Easy to set up
  • Works everywhere (even behind firewalls)
  • No additional configuration needed

Cons:

  • Need to enter credentials (though Git can remember them with credential helper)
  • Uses Personal Access Token instead of password

Method 2: SSH (More Convenient Long-term)

Pros:

  • No need to enter credentials after setup
  • More secure with public-key cryptography
  • Preferred by many developers

Cons:

  • Requires initial key generation and setup
  • May not work in some corporate networks
  • Slightly more complex for beginners

Which should you choose?

Start with HTTPS if you're new—it's simpler. You can always switch to SSH later once you're comfortable with the basics.

We'll cover both methods so you can choose what works best for you!

Method 1: HTTPS Authentication

Step 1: Create a Personal Access Token

GitHub no longer accepts passwords for Git operations. You need a Personal Access Token (PAT) instead.

  1. Go to GitHub Settings (click your profile photo → Settings)
  2. Scroll down to "Developer settings" (bottom left)
  3. Click "Personal access tokens" → "Tokens (classic)"
  4. Click "Generate new token" → "Generate new token (classic)"
  5. Give it a descriptive note (e.g., "My Laptop Git Access")
  6. Select expiration (recommend 90 days for learning, or custom)
  7. Select scopes:
    • ✅ repo (full control of private repositories)
    • ✅ workflow (if you'll use GitHub Actions)
  8. Click "Generate token"
  9. IMPORTANT: Copy the token immediately! You won't be able to see it again.

Save your token securely!

Treat it like a password. Store it in a password manager. You'll need it when Git asks for a password.

Step 2: Add Remote with HTTPS URL

In your local repository, add the GitHub remote:

BASH
# Navigate to your repository
cd my-first-repo

# Add the remote (replace USERNAME and REPO with yours)
git remote add origin https://github.com/USERNAME/REPO.git

# Example:
git remote add origin https://github.com/sarahjohnson/my-first-repo.git

Step 3: Verify Remote

BASH
git remote -v

You should see:

TEXT
origin  https://github.com/USERNAME/REPO.git (fetch)
origin  https://github.com/USERNAME/REPO.git (push)

Using Your Token

When you push for the first time, Git will ask for credentials:

  • Username: Your GitHub username
  • Password: Paste your Personal Access Token (not your GitHub password!)

💾 Credential Storage

Git can remember your credentials so you don't have to enter them every time. Your credential helper (set up in lesson 3) should store your token securely after the first use.

Method 2: SSH Authentication

Step 1: Check for Existing SSH Keys

BASH
# Check if you already have SSH keys
ls -al ~/.ssh

Look for files named id_rsa.pub, id_ed25519.pub, or similar. If you see them, you already have SSH keys!

Step 2: Generate SSH Keys (if needed)

BASH
# Generate new SSH key (use your GitHub email)
ssh-keygen -t ed25519 -C "your.email@example.com"

# If your system doesn't support ed25519:
ssh-keygen -t rsa -b 4096 -C "your.email@example.com"

When prompted:

  • File location: Press Enter to use default
  • Passphrase: Optional but recommended for security

Step 3: Add SSH Key to SSH Agent

On macOS/Linux:

BASH
# Start the ssh-agent
eval "$(ssh-agent -s)"

# Add your key
ssh-add ~/.ssh/id_ed25519

On Windows (Git Bash):

BASH
# Start the ssh-agent
eval `ssh-agent -s`

# Add your key
ssh-add ~/.ssh/id_ed25519

Step 4: Copy Your Public Key

On macOS:

BASH
# Copy to clipboard
pbcopy < ~/.ssh/id_ed25519.pub

On Linux:

BASH
# Display key (then copy manually)
cat ~/.ssh/id_ed25519.pub

# Or use xclip if installed
xclip -selection clipboard < ~/.ssh/id_ed25519.pub

On Windows:

BASH
# Display key (then copy manually)
cat ~/.ssh/id_ed25519.pub

# Or copy to clipboard
clip < ~/.ssh/id_ed25519.pub

Step 5: Add SSH Key to GitHub

  1. Go to GitHub Settings (click your profile photo → Settings)
  2. Click "SSH and GPG keys" in the sidebar
  3. Click "New SSH key"
  4. Give it a descriptive title (e.g., "My Laptop")
  5. Paste your public key in the "Key" field
  6. Click "Add SSH key"
  7. Confirm with your GitHub password if prompted

Step 6: Test SSH Connection

BASH
ssh -T git@github.com

You should see:

TEXT
Hi USERNAME! You've successfully authenticated, but GitHub does not provide shell access.

If you see this message, SSH is working! Don't worry about the "does not provide shell access" part—that's normal.

Step 7: Add Remote with SSH URL

BASH
# Navigate to your repository
cd my-first-repo

# Add the remote (replace USERNAME and REPO with yours)
git remote add origin git@github.com:USERNAME/REPO.git

# Example:
git remote add origin git@github.com:sarahjohnson/my-first-repo.git

Step 8: Verify Remote

BASH
git remote -v

You should see:

TEXT
origin  git@github.com:USERNAME/REPO.git (fetch)
origin  git@github.com:USERNAME/REPO.git (push)

Working with Remotes

Viewing Remotes

BASH
# List remotes (short)
git remote

# List remotes with URLs
git remote -v

# Show detailed info about a remote
git remote show origin

Adding Remotes

BASH
# Add a remote
git remote add <name> <url>

# Example with HTTPS
git remote add origin https://github.com/user/repo.git

# Example with SSH
git remote add origin git@github.com:user/repo.git

# You can have multiple remotes with different names
git remote add upstream https://github.com/original/repo.git

Renaming Remotes

BASH
# Rename a remote
git remote rename old-name new-name

# Example: rename origin to github
git remote rename origin github

Changing Remote URL

BASH
# Change remote URL (useful when switching between HTTPS and SSH)
git remote set-url origin new-url

# Switch from HTTPS to SSH
git remote set-url origin git@github.com:user/repo.git

# Switch from SSH to HTTPS
git remote set-url origin https://github.com/user/repo.git

Removing Remotes

BASH
# Remove a remote
git remote remove <name>

# Example
git remote remove origin

🏷️ About Remote Names

origin is just a convention—it's the default name for your primary remote. You can name it anything:

  • origin - Primary remote (conventional)
  • upstream - Original repo (when you've forked)
  • github, gitlab, bitbucket - Platform-specific
  • production, staging - Environment-specific

Your First Push to GitHub

Now that your remote is configured, let's push your code to GitHub!

Step 1: Check Your Branch Name

BASH
git branch

Make sure you're on main (or master).

Step 2: Push to GitHub

BASH
# Push and set upstream
git push -u origin main

# If your branch is named 'master':
git push -u origin master

The -u flag (short for --set-upstream) tells Git to remember that main should push to origin/main. After this first push, you can just use git push.

What Happens During Push

You'll see output like:

TEXT
Enumerating objects: 12, done.
Counting objects: 100% (12/12), done.
Delta compression using up to 8 threads
Compressing objects: 100% (8/8), done.
Writing objects: 100% (12/12), 1.23 KiB | 1.23 MiB/s, done.
Total 12 (delta 2), reused 0 (delta 0)
remote: Resolving deltas: 100% (2/2), done.
To github.com:username/my-first-repo.git
 * [new branch]      main -> main
Branch 'main' set up to track remote branch 'main' from 'origin'.

Congratulations! Your code is now on GitHub! Go to your repository URL in a browser to see it:

https://github.com/YOUR-USERNAME/YOUR-REPO

Understanding Upstream Tracking

When you use git push -u origin main, you're setting up an upstream tracking relationship.

What Does This Mean?

Your local main branch now "tracks" the remote origin/main branch. This means:

  • Git knows where to push when you run git push
  • Git knows where to pull from when you run git pull
  • Git can tell you if your branch is ahead or behind the remote

Checking Tracking Info

BASH
# See tracking branches
git branch -vv
TEXT
* main a1b2c3d [origin/main] Latest commit message

The [origin/main] shows this branch tracks origin/main.

Practice Remote Commands

Try these commands to practice working with remotes:

Practice Git Remote Commands

Experiment with viewing and managing remotes

$

Try these examples:

Troubleshooting Common Issues

Issue: Remote Already Exists

Error: "remote origin already exists"

Solution:

BASH
# Option 1: Remove and re-add
git remote remove origin
git remote add origin <url>

# Option 2: Update URL
git remote set-url origin <new-url>

Issue: Permission Denied (SSH)

Error: "Permission denied (publickey)"

Solutions:

  • Check SSH key is added to ssh-agent
  • Verify public key is on GitHub
  • Test SSH connection: ssh -T git@github.com
  • Try using HTTPS instead if SSH continues to fail

Issue: Authentication Failed (HTTPS)

Error: "Authentication failed"

Solutions:

  • Make sure you're using a Personal Access Token, not your password
  • Check token has correct permissions (repo scope)
  • Verify token hasn't expired
  • Clear credential cache and try again

Issue: Push Rejected

Error: "Updates were rejected because the remote contains work that you do not have locally"

Solution: Pull first, then push:

BASH
git pull origin main
git push origin main

Best Practices

1. Use SSH for Convenience

Once set up, SSH doesn't require entering credentials. Great for daily use.

2. Keep Tokens Secure

Never commit Personal Access Tokens to your repository! Store them in a password manager.

3. Use Descriptive Remote Names

If you have multiple remotes, use clear names:

BASH
git remote add origin git@github.com:you/your-repo.git
git remote add upstream git@github.com:original/repo.git
git remote add production https://deploy.service.com/repo.git

4. Set Upstream on First Push

Always use -u on your first push to set up tracking:

BASH
git push -u origin main

5. Verify Before Pushing

BASH
# Check what you're about to push
git log origin/main..HEAD

# Check remote is correct
git remote -v

Command Reference

Here's a quick reference of remote commands:

BASH
# Viewing Remotes
git remote                   # List remote names
git remote -v                # List remotes with URLs
git remote show <name>       # Detailed remote info

# Adding Remotes
git remote add <name> <url>  # Add new remote

# Changing Remotes
git remote rename <old> <new>      # Rename remote
git remote set-url <name> <url>    # Change URL
git remote remove <name>           # Remove remote

# Pushing
git push -u origin main      # Push and set upstream
git push                     # Push to tracked remote
git push origin main         # Push to specific remote/branch

# SSH Key Management
ssh-keygen -t ed25519 -C "email"   # Generate SSH key
ssh-add ~/.ssh/id_ed25519          # Add key to agent
ssh -T git@github.com              # Test connection

Key Takeaways

  • Remote repositories are Git repositories hosted on servers like GitHub
  • origin is the conventional name for your primary remote
  • HTTPS uses Personal Access Tokens; SSH uses cryptographic keys
  • git remote add connects your local repo to GitHub
  • git push -u origin main pushes code and sets up tracking
  • SSH is more convenient after initial setup; HTTPS is simpler to start
  • Never use your GitHub password for Git—use tokens or SSH keys
  • You can have multiple remotes with different names
  • Upstream tracking makes git push and git pull work without specifying the remote
  • Always verify your remote configuration before pushing

What's Next?

Excellent work! You've successfully connected your local Git repository to GitHub and pushed your code. Your projects are now backed up in the cloud and ready to share with the world.

In the next lesson, we'll dive deeper into pushing and pulling code. You'll learn how to keep your local and remote repositories synchronized, handle updates from GitHub, work with different branches on remotes, and understand the complete workflow of collaborative development. This is where Git really becomes powerful for teamwork!

🎯 Practice Assignment

Before the next lesson:

  1. Create 2-3 repositories on GitHub
  2. Connect them to local repositories with git remote add
  3. Push your code to GitHub with git push -u origin main
  4. Visit your repositories on GitHub to verify they're there
  5. Try both HTTPS and SSH (if you're comfortable)
  6. Practice viewing remote info with git remote -v and git remote show origin

Test Your Understanding of Connecting to GitHub

Question 1 of 4

What is a remote repository?

Current Score0 / 0

Know someone who'd find this guide helpful? Please share!

Previous
Undoing Changes
Next
Pushing & Pulling Code

Never Miss a New Git & GitHub Tutorial

Join 2,000+ developers learning Git & GitHub step-by-step. Get new tutorials, tips, and exclusive resources delivered to your inbox - completely FREE.

You might also like

UI Components

Ready-made components for your projects

Developer Tools

Boost productivity with handy generators

HTML Game

Learn HTML concepts through interactive gameplay

Join Our Web Development Training Program

Master frontend & backend development with hands-on projects.

Git & Github Tutorials

0 of 20 completed

Your Progress0%

Topics

Getting Started

  • What is Git?
  • What is GitHub?
  • Installing & Configuring Git
  • Your First Git Repository

Core Git Concepts

  • Understanding Commits & History
  • Working with Branches
  • Merging Branches
  • The Staging Area
  • Undoing Changes

Working with GitHub

  • Connecting to GitHub
  • Pushing & Pulling Code
  • Cloning Repositories
  • GitHub README & Documentation

Collaboration Workflows

  • Forking & Pull Requests
  • Code Review Basics
  • Handling Merge Conflicts
  • Issues & Project Management

Best Practices & Workflows

  • Git Workflow Best Practices
  • Working with .gitignore
  • Common Git Problems & Solutions
Falytom logoFALYTOM

Learn technologies like HTML, CSS, JavaScript, React, NodeJS and more through interactive games, tutorials, components and free tools. Transform your businesses with AI chatbots, SEO-optimized websites, and professional development services.

© 2025 Tomilola Group
  • Facebook logo
  • Twitter logo
  • Instagram logo
  • LinkedIn logo
  • GitHub logo
  • YouTube logo