-
Notifications
You must be signed in to change notification settings - Fork 2
backup and version control via git
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!
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.R
…
final_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
.
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:
File -> New project -> Existing directory
and
Tools -> Version control -> Project setup -> git
File -> Open project
- Click
Git
next to the tabsEnvironment
andHistory
- For the files you want to backup check the box in the column called
Staged
- Press the
Commit
button and write a commit message and pressCommit
.
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”.
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.