12.2 Using version control with Git

Tools: Git, GitHub or GitLab

These tools let you take control of the versions of you project workflow.

12.2.1 Why version control?

  • code disappeared
  • need to integrating changes in my Team’s project workflow
  • several people can synchronize and collaborate on a same project
  • find something back from far way in time
  • safely track changes

More info on how to download and install Git and GitHub are located elsewhere: Happy Git book

We assume the following:

  1. You’ve registered a free GitHub account

  2. You’ve installed/updated R and RStudio

  3. You’ve installed Git

  4. You’ve introduced yourself to Git

  5. You’ve confirmed that you can push to / pull from GitHub from the command line

  6. You will also need a test repository on GitHub

12.2.2 Git basics: add - commit - push - pull

New users might be challenged for username and password. Many general Git tools require authentication. The information that is needed is your PAT.

You can stored your PAT with gitcreds::gitcreds_set() command. Once this is done correctly you don’t need to do that again unless you require more strict rules on your VC tool, so that it might require you to regularly update your credentials.1

The basic commands in Git are:

  • add: info or other addition to the project

    (i.e. Add a line to README and verify that Git notices the change)

  • commit: engage the content with the repository

    (i.e. in RStudio click the bottom “commit” in the pane section of GitHub)

    The “commit” button creates a unique commit reference number: sha#

    And allows the user to make a comment about the commit, so to advise the others in the project or to remind the user about it.

  • push: send the content to the server and so to the repository

  • pull: receive the changes/updates from the repository

12.2.3 About branches

The “main” branch is the one that appears at the beginning of the project, but other branches can be created. Secondary branches are work areas, usually for the other in the team to have a further layer of security of the “main” content.

When you work on a shared project, your collaborators need to name a new branch to interact with the repository. This imply the creation of mirrored repositories that can be absolutely equal or slightly different, as the requested additions/modifications are accepted.

12.2.4 Issues

Issues are another way to advise the main repository of some modifications that would be needed. They are used to propose changes, to track a bug or to suggest a feature, and can be done directly by the GitHub page of the repository. An issue creates a “message exchange” form of communication with the repository owner, for advising about something that can be improved.