Connect GitHub to Git

Avatar Dr. T | May 13, 2018 138 Views 0 Likes 5 On 3 Ratings

138 Views 5 On 3 Ratings Rate it

So, you have a GitHub account and you want to update your repos to your local computer so that you can start using the power of Git in conjunction with GitHub. Brilliant idea! As long as I have been working as a developer, GitHub has been my favorite tool because I can start a project, create branches, work on teams with other devs, and deploy my apps all from my command line using Git and GitHub as my storage.

In this tutorial, I will take you through a quick setup of connecting Git and GitHub on our local machines so that we can push updates to GitHub as a safe place to keep our code in case something happens to our machines. You will need to use your terminal to do so.

1. Create a GitHub.com account if you don’t already have one

Check out the “Create a GitHub Account” tutorial if you don’t already have a GitHub account. It is really easy to create an account.

2. Open Your Command Line App

Now it’s time to hit the command line.

On OS X, you’ll use the Terminal by navigating to Applications > Utilities > Terminal as is shown in the image below. Double-click the Terminal App for it to open.

On Windows, you’ll need to start the Git Bash app. You can find it by searching “git bash” as is shown in the image below. If you do not have this app, skip to the next step — “Install Git”.

 

3. Install Git

Check to see if you already have git installed by running the following code in your terminal

git --version

If a version is printed on the next line, then you already have git installed and can skip to the next step — “Open Your Command Line App”.

NOTE: Your version of Git may be more recent than what is in the image below.

If Git is not installed, you can install Git for Windows, Mac or Linux by following the instructions provided on the Git website

4. Set Your User Name in Git

It’s time to configure Git. Type in the following code:

git config --global user.name "PUT YOUR NAME HERE"

You’ll need to replace “PUT YOUR NAME HERE” with your own name in quotations. You can use your legal name, online handle, or anything you’d like. It doesn’t matter to Git what name you use, but keep it professional if it matters to you. Git uses this info to credit commits and future projects.

5. Set Your Email in Git

Next, input your email making sure to use the same email you used when you signed up for a GitHub.com account. Copy and paste this into the command line replacing YOUR email address where “your_email@youremail.com” is located in the code snippet.

git config --global user.email "your_email@youremail.com"

That’s all you need to do to get started using Git on your computer.

However, if you set up a GitHub.com account, it’s likely you don’t just want to manage your project locally, but also online.

If you want you can also set up Git so it doesn’t ask you to log in to your GitHub.com account every time you want to talk to it. 

5. Generating a new SSH key for GitHub

The full tutorial on how to set this section up is on GitHub. I will show you below how to quickly get set up, but if you would like more detailed info, visit GitHub for more information.

– Paste the text below, substituting in your GitHub email address.

ssh-keygen -t rsa -b 4096 -C "your_email@example.com"

– When you’re prompted to “Enter a file in which to save the key,” press Enter. This accepts the default file location.

Enter a file in which to save the key (/Users/you/.ssh/id_rsa): [Press enter]

At the prompt, type a secure passphrase. You can use any passphrase, you will just need to remember it. Using your system password is fine here as well. For more information, see “Working with SSH key passphrases”.

Enter passphrase (empty for no passphrase): [Type a passphrase]
Enter same passphrase again: [Type passphrase again]

6. Adding your SSH key to the ssh-agent

Again, this info can be found on GitHub, but I am including the steps here for reference.

– Start the ssh-agent in the background.

eval "$(ssh-agent -s)"

– Add your SSH private key to the ssh-agent and store your passphrase in the keychain. If you created your key with a different name, or if you are adding an existing key that has a different name, replace id_rsa in the command with the name of your private key file.

ssh-add -K ~/.ssh/id_rsa

7. Adding a new SSH key to your GitHub account

Follow the steps located here to add your key to your GitHub Account

Conclusion 

You should be all set to go! Now when you create a repo in GitHub, you can connect it to your local machine and hammer away at the code. Great job!

Happy Coding!

Dr. T


Comments

This post currently has one response.

Comments are closed.