Git and GitHub Setup

In addition to using git, which you’re already doing, you should also clone the class repo from GitHub.

Note: remember that you are not creating your own GitHub repo for this class, nor pushing to it. These instructions are just about downloading your own copy of my files in the common way.

Before you clone the class repo, you need to make sure that:

  1. Git is installed on your computer.
  2. Git knows your name and email address.
  3. You have a GitHub account.
  4. Your computer has an SSH key.
  5. GitHub knows about that SSH key.

You normally only need to do this setup once per computer.


1. Make sure you have a GitHub account

Go to:

https://github.com

If you do not already have an account, create one.

Remember your GitHub username; you will use GitHub throughout the course, and throughout life.


2. Make sure Git is installed

Open a terminal.

Run:

git --version

If you see something like:

git version 2.43.0

you already have Git installed.

If Git is not installed, install it before continuing.

☞ Ubuntu/Linux

sudo apt install git

☞ macOS

Run:

xcode-select --install

and follow the instructions that appear.

☞ Windows

Download and install Git for Windows from:

https://git-scm.com/download/win

After installing it, close and reopen PowerShell.


3. Tell Git who you are

Git records the author of every commit.

Run these commands, substituting your own name and email address:

git config --global user.name "Your Name"
git config --global user.email "you@example.com"

You can check the result with:

git config --global --list

4. What is an SSH key?

When your computer communicates with GitHub, GitHub needs a way to know that you really are you.

One common way to do this is with an SSH key.

An SSH key actually consists of two related files:

The private key is secret. Never email it, upload it, or give it to anyone.

The public key is safe to share. Once you give the public key to GitHub, GitHub can recognize connections made using the corresponding private key on your computer.

You can think of the public key as telling GitHub:

“This particular computer is allowed to act as me.”

We are going to create an SSH key on your computer and then give GitHub the public half of it.


5. Create an SSH key

Open your terminal or PowerShell and run:

ssh-keygen -t ed25519

You will see a prompt similar to:

Enter file in which to save the key:

Press Enter.

This accepts the normal default filename and location.

Next, you will be asked for a passphrase:

Enter passphrase (empty for no passphrase):

For this course, it is okay to press Enter to leave the passphrase empty.

It will ask again:

Enter same passphrase again:

Press Enter again.

You should now have two new files.

☞ Linux:

They will normally be:

~/.ssh/id_ed25519
~/.ssh/id_ed25519.pub

☞ macOS:

They will normally be:

~/.ssh/id_ed25519
~/.ssh/id_ed25519.pub

☞ Windows:

They will normally be inside the .ssh folder in your home folder.

The file:

id_ed25519

is your private key.

Do not share it.

The file:

id_ed25519.pub

is your public key.

That is the one we are going to give to GitHub.


6. Display your public key

☞ Linux

Run:

cat ~/.ssh/id_ed25519.pub

☞ macOS

Run:

cat ~/.ssh/id_ed25519.pub

☞ Windows PowerShell

Run:

Get-Content $HOME\.ssh\id_ed25519.pub

You should see one long line beginning with something like:

ssh-ed25519

Select and copy that entire line.

Do not copy the contents of id_ed25519.

You want the file whose name ends in:

.pub

7. Add your public key to GitHub

In GitHub:

  1. Click your profile picture in the upper-right corner.

  2. Choose Settings.

  3. Choose SSH and GPG keys.

  4. Click New SSH key.

  5. Give it a useful title, such as:

    My laptop
  6. Leave the key type as Authentication Key.

  7. Paste the entire public key you copied into the Key box.

  8. Click Add SSH key.

GitHub now knows that your computer’s SSH key belongs to your account.


8. Test the connection

Return to your terminal or PowerShell and run:

ssh -T git@github.com

The first time you do this, you may see a message asking whether you trust GitHub’s host.

It may end with something like:

Are you sure you want to continue connecting (yes/no/[fingerprint])?

Type:

yes

and press Enter.

If everything is working, you should then see a message similar to:

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

The important words are:

You've successfully authenticated

Your computer can now communicate with GitHub using SSH.


9. Clone the class repo

Now you can download your own local copy of the DATA 419 repository.

First, use cd to navigate to your home folder. Open a terminal and type cd by itself, then press Enter.

Then run:

git clone git@github.com:divilian/data419.git

Git will create a new folder called:

data419

Move into it:

cd data419

You now have your own local copy of the class repository.


10. Verify that it worked

You can ask Git where the repository came from:

git remote -v

You should see something containing:

git@github.com:divilian/data419.git

You can also list the files.

☞ Linux:

ls

☞ macOS:

ls

☞ Windows PowerShell:

Get-ChildItem

You should now see the files from the class repository.


Troubleshooting

Permission denied (publickey)

If you see:

Permission denied (publickey).

then GitHub is not recognizing your SSH key.

First try:

ssh -T git@github.com

If that does not report that you successfully authenticated, check that:

  1. you created the SSH key,
  2. you copied the contents of id_ed25519.pub, not id_ed25519,
  3. you added that public key to the correct GitHub account, and
  4. you copied the entire public-key line.

ssh-keygen is not recognized

If Windows says that ssh-keygen is not recognized as a command, make sure Git for Windows has been installed, then close and reopen PowerShell.

I already have an SSH key

If you discover that you already have files named:

id_ed25519
id_ed25519.pub

you do not need to create another key.

You can simply display the existing .pub file and add that public key to GitHub.