Setting Up Github with a PAT

Accessing the Terminal app on Mac

Before you can even start using Git on your computer, you have to be able to access Terminal. That is where Git commands will take place.

To open up Terminal on Mac, run the following shortcut on your keyboard followed by hitting the return key:


Command key + Space key
                

And a big input field with the placeholder text "Spotlight Search" will appear in the top left corner of your computer screen.

Screenshot of Spotlight Search

Next, inside that input field, type Terminal.

Screenshot of typing Terminal in Spotlight Search

Then click on the highlighted selection, and a window instance of Terminal will appear. Now you are ready to use it.

One thing to note is that whenever you initially open up Terminal, it opens up in your computer's Home directory, which is represented by the tilde ~ symbol in your Terminal window instance.

Signing Up for a Github Account

First you have to sign up for a Github account before you can take advantage of all it has to offer! Please visit github.com to sign up.

Git is already installed on the School Computers

Git is already installed on the School computers, but since the course is online now, you will have to install it on your own computers. I have included a couple of links about to how to install Git for those of you that might not have it installed at home.

Checking if you have Git installed on your computer

If you are on a Mac, to check whether you have Git installed on your computer, type the following command in Terminal and then hit the return key:


git --version
                
If you have Git installed, something like the following should print out to the Terminal Console:

git version 2.x.x
                

If you don't have Git installed

On macOS systems you should have Git installed. Homebrew is great for installing packages you need on your MacOS.

But to make your life easier and the install go more quickly, don't install Git with Homebrew. Leave that for another day. Since by now you have installed Xcode, Git comes as part of the package.

Configuring your Github email

Whether you are configuring your email for Github at School or at home, this step remains the same.


git config --global user.name "Emma Paris"
$ git config --global user.email "eparis@atlassian.com"
                

Make sure to replace Emma's name with yours, and Emma's email with yours when you do this step!

Note: If you want to do anything on Github outside of your own repositories and don't want to encounter any problems, DON'T keep your email private there. Just make sure then that you use an email you don't mind making public. You should take advantage of everything that Github has to offer, including creating issues on the repositories of tools you love to use!

Authenticating on Github with a PAT

Before August 13, 2021, it used to be that you could authenticate yourself using your Github username and password via the Command Line on your local machine before pushing local repository changes to Github. This was called authenticating with HTTPS. We still authenticate with HTTPS, but just inputting our username and password to do so is not enough.

Now, if you want to authenticate on Github using HTTPS, you first have to create a Personal Access Token on Github.

PATs on Github

Personal Access Tokens have replaced using usernames and passwords for authentication to GitHub when using the GitHub API or the Command Line.

As a security measure, GitHub automatically removes personal access tokens that haven't been used in a year. To provide additional security, Github highly recommends adding an expiration to your personal access tokens.

A token with no assigned scopes can only access public information. For more information on scopes, see "Available scopes".

Verifying your email address

First verify your email address, IF it has not been verified yet. To learn about how to verify your email address with Github, please visit Verifying your email address for Github.

Creating a PAT

In the right hand corner of any page on Github, click on your profile photo/avatar, and then select "Settings" from the dropdown that appears.

Screenshot of the user account menu on Github

To access Github's documentation on creating a personal access token, you can visit Creating a personal access token.

Accessing the Developer Settings

Once you have entered your account "Settings" area, in the left hand side bar, you will see a tab called "Developer Settings".

Screenshot of the user account Settings menu on Github

Click on "Developer Settings" to enter it.

To access Github's documentation on creating a personal access token, you can visit Creating a personal access token.

The Personal access tokens tab

When you click on the "Developer Settings" tab, you are taken to the GitHub Apps area.

In the left hand side bar, you will see a tab called "Personal access tokens". Click on that.

Screen Shot of the Github Apps area in the user account Developer Settings

To access Github's documentation on creating a personal access token, you can visit Creating a personal access token.

Generating a new token

After you have clicked on the "Personal access tokens" tab, you are taken to the "Personal access tokens" area.

To the right of the "Personal access tokens" heading, you will see a button with the text "Generate new token". Click on that.

Screenshot of Personal Access Tokens area in the user account Settings

To access Github's documentation on creating a personal access token, you can visit Creating a personal access token.

Naming your new token

After you have clicked on the "Generate new token" button, an input field will appear with the title "Note". Below the input field is the text "What's this token for?". Create a descriptive name for your token so that you will remember why you created it and what you are primarily using it for.

To access Github's documentation on creating a personal access token, you can visit Creating a personal access token.

Selecting an expiration date for your token

As mentioned earlier, Github highly recommends selecting an expiration for your personal access token for security purposes. To give your personal access token an expiration, select the Expiration dropdown menu, click on a default selection, or use the calendar picker.

To access Github's documentation on creating a personal access token, you can visit Creating a personal access token.

Selecting scopes for your token

As mentioned earlier, if you do not explicitly set any scopes for your personal access token, you would only be able to use it to access public information/repositories on Github. That includes your own repositories as well.

For the purposes of complete inclusion, select ALL available scopes to grant your token.

To access Github's documentation on creating a personal access token, you can visit Creating a personal access token.

Actually generating your new token

All the previous steps are set up steps needed before you actually generate your new token.

Once you have completed selecting the scopes you want to apply to your new personal access token, you can finally click on the green "Generate token" button.

To access Github's documentation on creating a personal access token, you can visit Creating a personal access token.

How to enable HTTPS authentication on Github

Now that you have set up and generated your new personal access token, you have to make sure that you are set up for it on Github.

When you create a repository on Github, make sure that the following has been selected within your green "Code" button in the "home page" of your repository.

Screen shot of inner contents of the Github repository Code button

In other words, make sure that HTTPS has been selected. Then, by default, all the other repositories you subsequently create will also have "HTTPS" selected there.

Github PAT authentication in VS Code

If you are using VS Code's Integrated Terminal, and you will be for this course, you have to make sure that VS Code recognizes your personal access token as well. Otherwise, you will not be able to push your local repository commits to your remote repositories to Github. In order to make that happen, you have to make sure that you have added the VS Code Github extension by KnisterPeter. It is among the extensions listed in the VS Code Installation and Set Up slide deck.

Setting up Github PAT authentication in VS Code

Once you have created a personal access token on Github, and you have added the Github extension in VS Code, you are ready to add Github authentication in VS Code using your personal access token.

First, open up the VS Code command palette by using the following keyboard shortcut:


Shift key + Command key + P key
                

And the following will appear at the top of the active VS Code window:

Screen shot of the VS Code command palette.

Next, as shown in the screen shot above, start typing the words personal access token, and Github: Set Set Personal Access Token will appear below the input field.

Next, copy and paste your personal access token into the input field, and then hit the return key on your keyboard. And that is it! Now you can start pushing your local repository commits to Github to your heart's content!

Now you should be good to go!

Now we are ready to git it on with Git on Github!

Related Resources