Section 5 Git (part one)

In the part one section of the book we will show you how to work with git on your local compute, without any regard to the external (remote) place such as GitHub. In part two we will show you how to work with external (remote) repositories hosted at GitHub

5.1 Introduction

Git is a version control tool, one of many tools, but it is very popular. Git was designed for tracking versions of software development, but it has been re-purpose for doing general tracking of text and data i.e scientific research.

Below is an illustration of the differences between do-it-yourself (DIY) version control system, and git version control. DIY version control systems are great with two caveats:

  • no one else will understand it
  • the future you will forget the awesome schema that you have invented
This is an example of git version control vs DIY versioning via filesystem

Figure 5.1: This is an example of git version control vs DIY versioning via filesystem

5.2 Git init

Let’s initiate new git repository, which is a lingo for marking our current folder special. From now on everything in that folder will be tracked by git. BUT we still have to actively save (commit) changes.

Tools
 └── Version Control
           └── Project setup
           
Version control system: git

Alternatively execute the following code in R console and re-launch RStudio project

system("git init")

Once that’s done, you should see new Git tab appearing in “Environment, History …” pane

— That was unusual …

5.3 Git commit

Let’s click on that new “Git” tab and select a couple of file and then click “commit” button.

  1. Select these files:
  • learning.Rmd
  • learning.html
  • presenting.Rmd
  • presenting.html

A new dialog should pop up, you should see this window 5.2

RStudio pop up dialog for git commit and other git related work

Figure 5.2: RStudio pop up dialog for git commit and other git related work

  1. Write down a commit message (free form, but keep it informative)

Let’s write the following text in the commit message box and press “commit”

saving my first Rmarkdown document
RStudio pop up dialog for git commit and other git related work with commit message

Figure 5.3: RStudio pop up dialog for git commit and other git related work with commit message

— happy days!

5.4 Git username and useremail

When you are using git for very first time on a new compute you will need to set up your username and email. Typically this is one off operation and almost always forgot about. But git will always remind you about that with the following message 5.4

RStudio pop up dialog showing additional step needs doing before using git

Figure 5.4: RStudio pop up dialog showing additional step needs doing before using git

Let’s execute the following two commands in R console pane, as suggested by the message. Note if you don’t use --global flag, then every new git repository will need those two commands (personal preference really).

system("git config --global user.name kirill")
system("git config --global user.email tskiril@gmail.com")

Let’s switch back to our commit, pop up, window close that messagea and click commit again.

— oops, forgot about that