GitHub

Authenticate Git to work with Github

Typically, you do this once (per computer)

If we want to push changes from our local repository to your Github cloud repository, Github must verify your credentials. Other software might just ask for your username and password, it’s a little different with Git. Basically there are two ways to connect with your remote repo (ssh and https), we will use https in this course.

First, create a personal access token (PAT) on Github

  1. Login into github.com, click on your user profile (top right) and click on “Settings”
  2. Choose Developer settings > Personal access tokens > Generate new token
  3. Add a descriptive note (e.g. https access from my personal laptop)
  4. Select scope “repo”
  5. Click on “Generate token”
  6. Copy your new personal access token (in the green box)
    • You won’t be able to see this token again
    • If you loose it, you can simply create a new one
    • If you want to store it, you neeed to treat this Personal access tokens (PAT) like a password. Only store it in a secure place (like a password management app) and never publish this PAT publicly

Then, store your PAT in you local Git

  1. In R, install the gitcreds package (install.packages("gitcreds"))
  2. Load this library (library("gitcreds"))
  3. Call the function gitcreds_set()
  4. Respond to the prompt with your PAT from the last step
  5. Check that you have stored a credential with gitcreds_get()

Create a repo on GitHub repo

Typically, you do this once per project

Now you can create a repository on Github that you can afterwards connect to your RStudio project from this week (which you will create in the next step). To do this, go to github.com and click on the plus sign in the top right corner, then fill in the following information:

  • Repository name: Give a meaningful name, e.g. cma-week2
  • Description: Give a meaningful description, e.g. Solving exercise 3 of the course "Computational Movement Analysis"
  • Make the repo public, not private
  • Choose Deselect Add a README file

Click on Create repository, then on the green button “Code”. Select HTTPS (it might already be selected) and then copy the URL by clicking on the clipboard symbol. The URL should look something list this https://github.com/GITHUB-USERNAME/cma-week2.git.

Connect your local repo with the remote repository

Typically, you do this once per project

In RStudio, open the RStudio project from week 3. Open the shell and follow the instructions described in …or push an existing repository from the command line in the website you were just forwarded to on Github (under https://github.com/GITHUB-USERNAME/cma-week2). These instructions should look something like this:

git remote add origin https://github.com/GITHUB-USERNAME/cma-week2.git
git push -u origin main

Type these commands line by line into your terminal. If you want to copy and paste the commands rather than type them: Note that ctrl + V for “pasting” won’t work via the keyboard shortcut, you will have to paste by right clicking into the terminal and choosing “paste”. Now refresh your repo on Github (https://github.com/GITHUB-USERNAME/cma-week2): You should now see the files from week 2 on GitHub. Didn’t work? 👉 Contact us!

Synchronize changes with GitHub

From now on, you should periodically synchronize your local changes with GitHub by pulling changes (from potential collegues) and pushing your own changes. You can do this via the git panel of the GUI (🠯 pull, 🠭 push), or via the git equivalent git commands:

git pull
git push