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
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
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
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.
- Select these files:
A new dialog should pop up, you should see this window 5.2
- 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”
— 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
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).
Let’s switch back to our commit, pop up, window close that messagea and click commit again.
— oops, forgot about that