Logo

dev-resources.site

for different kinds of informations.

How to Link git to GitHub via SSH on Windows

Published at
1/8/2025
Categories
git
github
webdev
programming
Author
rowleks
Categories
4 categories in total
git
open
github
open
webdev
open
programming
open
Author
7 person written this
rowleks
open
How to Link git to GitHub via SSH on Windows

As a developer, learning about github can feel great at first, I mean who doesn't need a secure cloud storehouse for their codes? The importance and use of git and GitHub cannot be overemphasized but there come a point in time where you just get tired and bored of always;

  1. Heading to github.com,
  2. Locating your repo
  3. Adding new files to the repo
  4. Clicking and dragging the files from your PC into GitHub
  5. And finally writing a commit message.

All these just to push your code to GitHub, what if you needed to make just a minor change? You'd have to go through that mini hell again? Actually, you don't have to because all these steps can be shortened to;

git add .
git commit -m "minor fix"
git push
Enter fullscreen mode Exit fullscreen mode

Yeah that's right, just these 3 commands above does all that work for you and fast.

But before you acquire such power, there's a price you'd have to pay. and that is, you'd have to setup a connection between git and GitHub first which luckily isn't that hard at all. I am going to share those steps in this post.

Β 

Step 1: Download and install git

Alright, the first step is to have git installed in your PC, if you already have it, great! If not just click here and download a version suitable for you PC

git website for downloading git

After download, start the install wizard and follow the prompts to install.

Upon installation of git, 3 other applications would also be automatically installed in your PC: Git cmd, Git GUI and Git Bash. These are just the different ways of interacting with git.

Configuring git

Open Git Bash, which should look similar to the image below

Git Bash for windows

Run these commands:

git config --global user.name "Your Name"

#This name will be associated with your commits 
Enter fullscreen mode Exit fullscreen mode
git config --global user.email "Your email Address"

#This email will be associated with your commits 
Enter fullscreen mode Exit fullscreen mode

You can verify that these has been set by running

git config --list
Enter fullscreen mode Exit fullscreen mode

Β 

Step 2: Generate SSH Key

Installing and configuring git was so easy right, now to an easy but not so easy step, generating an SSH key;

What is an SSH key and why do we need it?

To answer that let's first understand what SSH even mean.
SSH stands for Secure Shell, and it's a network protocol (like HTTPS but different) that allows secure communication between devices over an insecure connection.

Meanwhile an SSH key is a pair of cryptographic keys (a public key and a private key) used to authenticate a secure connection between your computer and a remote server (in this case, GitHub). Put simply, it's a file containing encrypted texts used for authetication.
We need it to authenticate to GitHub without our username or password.

To generate the key, open Git Bash and run these commands:

ssh-keygen -t rsa -b 4096 -C "[email protected]"

#Replace "[email protected]" with the email address associated with your GitHub account.
Enter fullscreen mode Exit fullscreen mode

Let's breakdown some of the command arguments above:

ssh-keygen - This generates a new SSH key pair (a public key and a private key)

-t rsa - This sets the type of SSH encryption to rsa (Rivest-Shamir-Adleman) which is the most widely used. Other types includes;
ECDSA (Elliptic Curve Digital Signature Algorithm)
ED25519 (Edwards-curve Digital Signature Algorithm 25519)

-b 4096 - This sets the number of bits of the generated key to 4096. The other possible value for rsa encryption is 2048 which is less secure.

-C [email protected] - This adds a comment to the key (usually your email address)

When prompted after running the above command, press Enter to accept the default file location for the file containing the generated SSH key.

Next, you can optionally set a passphrase for extra security or simply leave the field blank and press Enter twice.

Lastly, copy the public key to your clipboard with the following command.

clip < ~/.ssh/id_rsa.pub
Enter fullscreen mode Exit fullscreen mode

or

cat ~/.ssh/id_rsa.pub
Enter fullscreen mode Exit fullscreen mode

This will display the public key on your Git Bash terminal, then you can manually highlight and copy the public SSH key

Β 

Step 3: Add SSH Key to Github and link to Github repository locally

Now for the third and final step, do these:

  1. Log in to your GitHub account.
  2. Go to Settings > SSH and GPG keys.
  3. Click New SSH key.
  4. In the Title field, add a descriptive name (e.g., "git ssh")
  5. Paste your public key into the Key field. (The one you copied earlier)
  6. Click Add SSH key.

Adding ssh key to github

Confirm successfull connection

To confirm the connection between git and GitHub, open Git Bash and run the command:

ssh -T [email protected]
Enter fullscreen mode Exit fullscreen mode

if connection was successful you'll a message similar to:

Hi <username>! You've successfully authenticated, but GitHub does not provide shell access.
Enter fullscreen mode Exit fullscreen mode

Else simply reply yes multiple times when prompted. Afterwards, run the first command again to reconfirm.

Linking to a GitHub repo from VS code terminal

Congratulations on Linking your git to your GitHub via SSH. Goodnews is you only need to go through all those linking steps once. Now comes the easiest part.

Goto GitHub and create a new repo or open an existing repo
Click on SSH

GitHub new repo
For a new repo without any files that looks like the above pic:
Click on SSH and copy the url

For an already existing repo with files, open the repo, click Code > click on the ssh tab and copy the url
Open your project folder in VS and click on Terminal > New Terminal
run the following command:

git clone [email protected]:rowleks/test-repo.git
Enter fullscreen mode Exit fullscreen mode

Next navigate to the recently cloned repo (folder) on your PC project folder and open the newly cloned repo in VS code

Open the VS code terminal and run the following commands

git add .
Enter fullscreen mode Exit fullscreen mode
git commit -m "Initial commit"
Enter fullscreen mode Exit fullscreen mode
git branch -M main
Enter fullscreen mode Exit fullscreen mode
git push origin main
Enter fullscreen mode Exit fullscreen mode

And that's it.

Subsequently all you need to do to push to GitHub from that repository are the commands:

git add .
git commit -m "commit message"
git push
Enter fullscreen mode Exit fullscreen mode

Thank you for reading! I hope this helped.

git Article's
30 articles in total
Favicon
πŸ›‘οΈ Security Measures: Safeguarding Your Codebase πŸ”’
Favicon
Unlock Your Coding Potential with the GitHub Copilot Global Bootcamp!
Favicon
Kickstart Your Developer Journey: A Beginner’s Guide to Software Development Success
Favicon
Git Commands Every Developer Must Know πŸ”₯
Favicon
check out this!
Favicon
Git Merge VS Git Rebase: Which One Should YOU Use?
Favicon
A quick and simple guide on how to make branches for open-source development
Favicon
Improving Your Productivity With Git Worktrees
Favicon
GitHub Makeover: Create a Profile README That Stands Out and Connects! πŸ‘¨β€πŸ’»
Favicon
How to Fix Git Issues: Committing and Pushing Without Pulling Causes Stuck Branches
Favicon
Undo Mistakes in Git: Revert, Reset, and Checkout Simplified
Favicon
My First npm Package!
Favicon
Mastering Git and GitHub: A Guide for New Team Members
Favicon
GIT hack: Sort and show recent branches
Favicon
GIT
Favicon
πŸŽ‰ Simplify Laravel CRUD Operations with Ease! πŸš€
Favicon
Why I Stopped Using Plain Git Pull (And Why You Should Too)
Favicon
Why I Built commit-ai: A Story About Git Security and Team Safety
Favicon
How to Link git to GitHub via SSH on Windows
Favicon
I built Zeet. A Git-like version Control System
Favicon
Effective Git Branch Merging for Teams πŸš€
Favicon
Mastering Git Workflows: Beyond Basic Commands
Favicon
Como enviar somente novos commits em uma branch que jΓ‘ mesclada.
Favicon
Getting Git to Work on Apple Silicon
Favicon
Git avanzado: ΒΏQuΓ© es cherry pick? πŸ’
Favicon
Git Cheatsheet that will make you a master in Git !
Favicon
How to upgrade Git to latest version on macOS
Favicon
Windows dotted paths
Favicon
Using git Conditionals to Manage Your Git Identities
Favicon
Can a Python Server (Serving HTML with Jinja2) Interact and Modify Files in a Jenkins Pipeline?

Featured ones: