Skip to content

backup and version control via git

Thomas Alexander Gerds edited this page Jan 9, 2022 · 1 revision

About

The R-studio provides a user-friendly way to use git. The version control software git should not be confused with GitHub which is a commercial website that lets you store your project elsewhere. On DST we cannot access the Internet and hence cannot connect with Github. Hence, this article is solely about git.

Disk space is expensive: Backup your code not your data!

Backup and version control

Motivation

To movitate the use of git let’s review the disadvantages of not using it. A commonly used backup strategy works by saving the current file with a new file name and then modify the new file, keeping the original as a backup copy:

final_analysis_1.R final_analysis_2.Rfinal_analysis_17.R

With this strategy it is difficult to know when and why a new version was started and there is no straightforward way to compare and look at the changes between version 3 and version 8 of a file. This strategy obviously clutters the working directory and it is prone to mistakenly modify/work with an old version. All these problems are not existent when using git.

Howto

Step 1: the R-studio project

The files which should have backup need to be placed in a directory folder. They can be distributed in sub-directories of this folder. The directory has to be associated with an R-studio project:

First time:

File -> New project -> Existing directory

and

Tools -> Version control -> Project setup -> git

All other times:

File -> Open project

Step 2: Adding the files to the git repository

  1. Click Git next to the tabs Environment and History
  2. For the files you want to backup check the box in the column called Staged
  3. Press the Commit button and write a commit message and press Commit.

The commit messages should explain why a new version of the file(s) was started. The first time message can simply be “Getting started”, the next messages should be more informative, e.g., “Backup: the current version produces all tables and figures for manuscript X”.

Step 3: Using the git system

When you change a file after its first commit git will mark the file as modified and you can see changes to the previous version, e.g., by using the click interface in R-studio. After several commits you can also see the history of a file.

The quality of a backup and version control system depends very much on the user using it. Remember to add all new important files to the git repository of your R-studio project.