2020-12-03

github.com/k-hench

Motivation

Images modified from Oto Godfrey and Justin Morton In coding-heavy science, reproducibility is key!

Version control (of which git is the most popular option) makes the development of your code traceable - it’s a time machine 😄

Using git and github has several of benefits:

  • organized version control
    (no final_vers_for_real_3.R files)
  • easy sharing/ collaboration (via github)
  • additional backup (on github)
  • easy archiving of code (via zenodo)
  • helps working with the computing cluster

\(\rightarrow\) it helps future you and others not getting lost in your coding

What is git

  • open source version control system
  • operates on a specific folder: the repository










git \(\neq\) github

git

  • the actual version control program
  • runs locally (on your computer)
  • allows to save your progress

github

  • online storage platform for git repositories
  • allows to exchange code with other people

\(\rightarrow\) accessability

git Basics

$ git init

$ git status
$ git add .
$ git comit -m <comment>

It begins

cd ~/Desktop
mkdir project_folder
cd project_folder
ls -a
#> .
#> ..
cd ~/Desktop/project_folder
git init
ls -a
#> Initialized empty Git repository in /home/usr_name/Desktop/project_folder/.git/
#> .
#> ..
#> .git

Saving Progress

git add .
git status
#> On branch master
#> Changes to be committed:
#>  modified:   file.txt
git commit -m "update"
#> [master e6716bf] update
#>  1 file changed, 2 insertions(+)

Progress History

A Note on Branches

You are initially on the branch called master …

… don’t worry about other branches for now!

Connecting to github

$ git remote add origin <url>

$ git push -u origin master

$ git pull origin master

Creating a github repository (1/2)

This is going to be the online version of our repository that can be accessed via github:






We are going to set this as the remote reference of our local repository and refer to it as origin.

If you already do have a github account, you can simply click here to create a new repository

Creating a github repository (2/2)

cd ~/Desktop/project_folder
git remote add origin https://github.com/k-hench/project_folder.git
git push -u origin master

Edits on github

Pull to local

To update the local repository on your laptop, you need to pull the latest commits from the remote.

git pull origin master

Setting the Remote

What about the

don’t panic part?

Using RStudio Projects

The RStudio git tab

Other GUIs