1.1 Git version control

What is it actually?

GitHub is an online interface which hosts and provides access to the Git version control system. Briefly, the software enables multiple users to work on a single (code) project, or workflow, without the need to share a common network. Following the principles of distributed revision control, each change to a file or folder is recorded, thus making any edit you’ve made comprehensible for other developers – and also making it easy to undo changes if something went terribly wrong!

For example, a short web-based tutorial to get started with the program is available from Try Git. At this point, we would like to invite you to take this roughly ten-minute tour to get used to the basic git commands that we are going to use repeatedly during the subsequent lessons.


hourglass



Initialize a new online code repository

Let’s get back to our own personal R business now. In order to be able to add version control to an RStudio project later on, you are required to create a user account at GitHub. This involves the specification of a username, e-mail address, and password only and goes without giving away personal data.

Once your account has been created and you’ve successfully logged in, select ‘New repository’ from the ‘Create new…’ (plus sign) drop-down menu in the top-right corner to create a new GitHub code repository.



Now, enter ‘advanced-programming-in-r’ as repository name and, optionally, provide a short description of the data it contains (or, more precisely, the data that it is supposed to contain in the future). Finally, hit the ‘Create repository’ button to complete the setup process.



So far, the code repository thus created is available online only. In order to get a local copy on your hard disk, copy the link to be found when hitting the green ‘Clone or download’ button on the main webpage of your GitHub repository. Next, open up a Git Bash or Terminal (depending on your operating system) and navigate to the folder where you intend to save local copies of your Git repositories in the future. Finally, run

git clone https://github.com/fdetsch/advanced-programming-in-r.git

(remember to replace the name) et voilà, all files associated with your online code repository are being downloaded to your destination folder. From now on, this will be the place for you to realize your coding work and, at the end of a day’s work, commit any changes to the online repository to better keep track of the latest changes to your code.


Task: Create a local SSH key

Before we can push files to the newly created online code repository, we have to create a SSH key (if not already present) for the local machine you are currently working on. For this purpose, follow the official GitHub tutorial on Generating SSH keys and, if necessary, create a SSH key locally and add it in your online account settings.


hourglass


Now that you successfully set up your (maybe first) own code repository, it is time to move on to the second crucial step towards establishing a consistently structured workflow in R: Setting up an RStudio Project and trace your tedious coding work using Git version control.