DEV Community

Mwangi Sharon
Mwangi Sharon

Posted on

Connecting Git Bash to GitHub: A Beginner’s Guide

What is covered in this part

Why connecting Git Bash to GitHub is important

In Part 1, we covered the basics of Git Bash and GitHub. Now, we’ll take the next step by connecting Git Bash to GitHub.

So why is connecting Git Bash to GitHub important? Connecting Git Bash to GitHub lets you move your work from your computer to GitHub and back again. Without this connection, Git can only track changes on your own computer, which means your work stays local and can’t be shared or backed up online.

When Git Bash is connected to GitHub, you can push your saved changes to GitHub, where your project is stored safely online.
You can also pull changes from GitHub, which is important when working on projects across multiple devices or with other people.

Yes, you read that right, multiple people can work on the same project without overwriting each other’s work, because Git keeps a clear history of changes and GitHub shows who made each update and when.

Connecting Git Bash to GitHub

Step 1: Create a GitHub account

You can create your GitHub account here.

Step 2: Configure your Git identity (name and email)

Git needs to know who you are so that it can label your commits correctly.
Now open Git Bash and type in your terminal:
To set your name

git config --global user.name "yourname"
Enter fullscreen mode Exit fullscreen mode

To set your email

git config --global user.email "youremail@example.com"
Enter fullscreen mode Exit fullscreen mode

To displays all Git settings that are currently configured on your computer.

git config --global --list
Enter fullscreen mode Exit fullscreen mode

You will be able to see your username and user-email displayed in the output.

Step 3: Generate a New SSH Key

You are probably wondering what Is an SSH Key?

Simply, an SSH key is a secure digital identity that allows Git Bash to connect to GitHub without typing your password every time.
And this is how we generate it:

ssh-keygen -t ed25519 -C "youremail@example.com"
Enter fullscreen mode Exit fullscreen mode

When prompted:

  • Press Enter to accept the default path/ file location.
  • Press Enter again to skip passphrase (or add one, optional). Example output:
Your public key has been saved in /c/Users/your-username/.ssh/id_ed25519
Enter fullscreen mode Exit fullscreen mode

You can also check if you have an already existing key using:

ls ~/.ssh
Enter fullscreen mode Exit fullscreen mode

Example output:

id_ed25519
id_ed25519.pub
Enter fullscreen mode Exit fullscreen mode

Step 4: Start the SSH Agent

This will start a background helper that securely holds your key.

eval "$(ssh-agent -s)"
Enter fullscreen mode Exit fullscreen mode

Example output:

Agent pid 293
Enter fullscreen mode Exit fullscreen mode

Step 5: Add Your Key to the Agent

Essentially, this tells the SSH agent which private key it should use to authenticate you.

ssh-add ~/.ssh/id_ed25519
Enter fullscreen mode Exit fullscreen mode

Example output:

Identity added: /c/Users/your-username/.ssh/id_ed25519
Enter fullscreen mode Exit fullscreen mode

Step 6: Copy Your Public Key

You can now use this code to displays your public key so you can copy it and add it to GitHub. The same key is also stored in the file path generated in step 3.

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

Example output:

ssh-ed25519 [YOUR_PUBLIC_KEY_HERE]
Enter fullscreen mode Exit fullscreen mode

After copying this public key, navigate to your GitHub account. Then paste it into GitHubSettingsSSH and GPG keys.
Settings

Step 7: Test the connection

This code helps you to confirm if Git Bash is now connected to GitHub.

ssh -T git@github.com
Enter fullscreen mode Exit fullscreen mode

Example output:

Hi your-username! You've successfully authenticated...
Enter fullscreen mode Exit fullscreen mode

👌Your GitHub and Git Bash are now connected.
Quick Tip: You only need to set up SSH once per computer and after this, GitHub authentication becomes seamless.

Feel free to engage with this post in the comment section. You can also check out Part 3 of the series.

Top comments (0)