Chapter 4 - Distributed Version Control (Git/GitHub)#

Authors: Daniel J. B. Clarke

Maintainers: Daniel J. B. Clarke

Version: 0.1

License: CC-BY-NC-SA 4.0


Setup#

Download & Install Git#

Git is a free and open source distributed version control system designed to handle everything from small to very large projects with speed and efficiency.

Download Git : https://git-scm.com/download

Git Documentation: https://git-scm.com/doc

Git Cheat Sheets: https://training.github.com/downloads/github-git-cheat-sheet/ https://ndpsoftware.com/git-cheatsheet.html

../../_images/9.png

Fig. 6 https://git-scm.com#

Create an Account on GitHub#

GitHub is a complete developer platform to build, scale, and deliver software. It’s primary use is for software development and version control using git.

GitHub Sign Up: https://github.com/signup

GitHub Documentation: https://docs.github.com

../../_images/10.png

Fig. 7 https://github.com#

Download & Install Visual Studio Code#

Visual Studio Code is a lightweight but powerful source code editor which runs on your desktop and is available for Windows, macOS and Linux.

Visual Studio Code Download: https://code.visualstudio.com/download

Visual Studio Code Documentation: https://code.visualstudio.com/docs

../../_images/11.png

Fig. 8 https://code.visualstudio.com#

Install Git Lens Visual Studio Code Extension#

GitLens supercharges Git within VS Code – Visualize code authorship at a glance via Git blame annotations and CodeLens, seamlessly navigate and explore Git repositories.

Install in Visual Studio Code:

Ctrl+P

ext install eamodio.gitlens

ext install eamodio.gitlens
../../_images/14.png

Fig. 9 https://gitlens.amod.io/#

Configuring Git#

First Time Git Setup#

The first thing you should do when you install Git is to set your user name and email address. This is important because every Git commit uses this information, and it’s immutably baked into the commits you start creating (for more information, see git’s docs on the subject).

Run these commands in your terminal after git is installed, replacing the name and email address with your own:

git config --global user.name "John Doe"
git config --global user.email johndoe@example.com

Configuring GitHub#

Creating an RSA Key-Pair for Secure GitHub Access#

Generating a new SSH key#

Adding a new SSH key to GitHub#

Creating a GitHub Repository#

Fork the Demo Project on GitHub#

https://github.com/ maayanlab /github-project-demo

Using Git#

Clone your Fork#

The username will change from maayanlab to your github username for your fork.

You can use Visual Studio Code and/or the git command line to clone the repository from the url.

Open & Explore the Project’s History#

History can be accessed both using Git Lens or via command line with git log --all --graph

Each item is a change to the code, changes can also be performed concurrently in other “branches”.

Social Coding#

A High Level Summary#

GitHub Pull Requests (PR)#

Pull Requests request to incorporate changes from one repository to another or from one branch to another through the github interface.

Git History & Other Tools on GitHub#

Conclusions#

In this lecture we:

  • Installed git & visual studio code & set up a github account

  • Forked a github repo

  • Learned git fundamentals

  • Used git to review the source code history

  • Used git to add our own changes

  • Used git to help with merging changes made in parallel

Appendix: GitHub Cheat Sheet#

https://education.github.com/git-cheat-sheet-education.pdf