Git Tutorial

Author

Pier

Git

https://git-scm.com/

Git is a version control system that tracks changes to files over time.

Why Git? Because Git is good, it’s right, it’s free.

The environment where versions are managed is the repository. A Git repository is the .git/ folder inside a project. This repository keeps track of all changes made to the project files, building a version history over time. In other words, if you delete the .git/ folder, you delete the project’s local history (game over).

Stage & Commit

Sooner or later, you’ll feel ready to add your progress to the repository. To do this, first you stage the files, and then you commit — that is, you create a new version of the files you selected.

To make a commit, you need to comment it — meaning you write a short descriptive sentence about the changes you made to the files/scripts/folders you’re committing.

Git tracks all changes made to the files, but it won’t save them in your local version until you stage and commit them.

GitHub

https://github.com/

Shared version control

GitHub is a platform for sharing repositories.

Owned by Microsoft, GitHub is essentially a hosting service — the cloud for all the repositories uploaded to it.

You can use it for free with upload limitations if you want to keep the repository private, or with more storage freedom but less privacy if you choose to make it public.

Repositories

From the website, you can view your own repositories and those you’ve been invited to collaborate on.

A repository

GitHub Account

At this point, you’ve signed up with a GitHub account. Among the many users, you might come across the divine TorTar — don’t worry, his are just digital hammer blows.

Download & Install Git

From the Git website homepage, download the latest version:

https://git-scm.com/

If you have a Mac, throw it away.

If you still have a Mac after throwing it away, follow the instructions on the site.

If you were thinking of a BigMac, follow me.

Configuration

Open the command prompt (press the Windows key → type “cmd” → press ENTER).

Run the following two lines of code:

git config --global user.name "username used on github"

git config --global user.email "email used on github"

You’ve just linked your information to all future commits you’ll make from your computer.

You can verify the configuration with the command:

git config user.name

Basic Git Commands

Dal pull al push, passando per lo stage e il commit.

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

For the laziest

There is a GitHub desktop app to manage your repositories without using the command prompt — especially useful if you don’t use an IDE to program.

https://desktop.github.com/

It saves you a few lines of code if you’re a devoted user of the laser mouse.

IDE and Git

Git is integrated into the most widely used IDEs — for example, RStudio (for the statistician who never has to ask), and Visual Studio Code (for those hunting pythons — and other creatures).

Pannello Git in RStudio

In both cases, if you’ve understood the Git workflow — from staging to commit, from push to pull — you’ll feel right at home and only need to write the commit message.

Pannello Git in Visual Studio Code

Only by popular demand, tutorials on how to initialize and use Git in both IDEs will follow.