Authenticating and Installing

Installing Git

Ask IT to install Git or GitHub Desktop. The later is more useful since you will get a good Git GUI and Git bundled together.

Authenticating

You need to authenticate in order to pull private repos and push to GitHub.

GitHub Desktop

No tokens needed.

  1. Sign in under GitHub Desktop > Settings (or Options) > Account.
  2. Fill out your user info on GitHub Desktop > Settings (or Options) > Account.
  3. Sign in at GitHub.com and ignore the GitHub Enterprise section, even if you use Enterprise Cloud. The Enterprise section if for signing into a Enterprise account on a private server.

Help! I signed up for GitHub Enterprise and GitHub Desktop will not authenticate!! Log out of GitHub Desktop under GitHub Desktop > Settings (or Options) > Account and log back in.

Visual Studio Code (VSCode)

No tokens needed but you will need Git installed. https://code.visualstudio.com/docs/sourcecontrol/github

  1. Install GitHub Pull Requests and Issues.
  2. Click on the GitHub icon in left nav bar and open a GitHub repo on your computer.
  3. Click on the GitHub icon (again) and sign into GitHub with your username and password.

Positron

Similar to VSCode. You log into your GitHub account with your username and password. If you need to work with repos in GitHub Enterprise, there’s a “GitHub Enterprise URI” Setting in Positron. Put in your enterprise url, e.g. https://github.com/enterprises/noaa-nmfs/ to clone internal repos.

GitKraken Desktop

No tokens needed. Log in with your GitHub account. https://help.gitkraken.com/gitkraken-desktop/github-gitkraken-desktop/

RStudio

Git and RStudio

In order for RStudio to use Git, it needs to know where your Git binary is installed. Instructions: https://happygitwithr.com/rstudio-see-git

Find Git binary

  1. In RStudio, Tools > Terminal > New Terminal
  2. At the command line (in the new terminal), type which git if on a Mac and where git if in Windows.
  3. Copy that path. It probably doesn’t matter which one you use if there are multiple listed.

Tell RStudio the Git binary location

  1. In RStudio, Tools > Global Options > Git/SVN
  2. There is a box at top that asks for the location of the Git binary.
  3. Paste that path in.

Authenticating

Install the R package usethis. Then run this code.

## set your user name and email:
usethis::use_git_config(user.name = "YourName", user.email = "your@mail.com")

## create a personal access token for authentication:
usethis::create_github_token() 

The typical scope that you want is repo and workflow (if you have GitHub Actions). Copy the token. It is really long. Copy that into YourPAT in code below.

## set personal access token:
credentials::set_github_pat("YourPAT")

Note for Linux users: credentials::set_github_pat() might store your PAT in a memory cache that expires after 15 minutes or when the computer is rebooted. You thus may wish to do extend the cache timeout to match the PAT validity period: usethis::use_git_config(helper="cache --timeout=2600000")

Configure your token for Enterprise

If you will be pushing and pulling from repos in GitHub Enterprise, you will need to Configure SSO. Click on the button next to the token and follow the instructions.

In terminal with a Personal Access Token

If you have authenticated with R following the instructions above, you do not need to authenticate again to use Git in the terminal. Conversely, if you authenticate in the terminal, you do not need to run the R code above.

  1. Go to https://github.com/settings/tokens
  2. Click generate new token.
  3. For most uses, set the scope to “repo”. Definitely do not click all the scopes!
  4. Copy the token that it generates.

Open a terminal window and type

git config --global user.email "<your email>"
git config --global user.name "<your name>"
git config --global pull.rebase false

Next in the terminal window type one of these

  • Unix: git config --global credential.helper store
  • Max: git config --global credential.helper osxkeychain
  • Windows: git config –global credential.helper manager-core

Now push a change to GitHub. It will ask for your username and password. For the password, end the token that you created.

In terminal with SSH

Instead of a token, you can use SSH keys to authenticate. Search “github authentication with ssh” for instructions.

More help

Here are some notes from the NMFS GitHub Governance Team. Only accessible if you have a NOAA email.