Introduction to Git - Fall 2020

Lecture 0: Setup

TOC

Slides: https://hackmd.io/@hpc2n-git-2020/L0-setup


Installing and setting up Git

We will use Git from the command line in this course. This is how you will use it on HPC2N's systems, and it will be easier to understand what is going on while you are learning to use Git.

Graphical tools exists for Git, see below list for a few. All entries on the list are free and unless otherwise mentioned for Windows, macOS, and Linux:


Installing and setting up Git - continued

  • Install Git, if you have not already
  • Create a repository with git init
  • Set your name and email with git config (local, global, system)
  • Test by creating a file
  • Then adding the file with git add
  • Then commiting the file with git commit

When this is done, you will clone the course materials.

NOTE: if you have a problem and want to use Kebnekaise, we have documentation for you.


Git install - Windows

  • Go to the Git-scm website (https://git-scm.com/downloads) and click "Windows" to download the Windows version. It will automatically start download of the .exe file.
  • The downloaded file can be installed by double-clicking and choosing "Run".
  • Click "Yes" to let it be installed and then "Next" to accept the GNU GPL.
  • The default options you are presented with should work, and we recommend using those.
  • NOTE: when it comes to choosing the default editor, we recommend using Vim, unless you have a preferred editor.

Git install - macOS

If you have installed XCode (or its Command Line Tools), Git may already be installed. To find out, open a terminal and enter git --version.

If Git is not installed, you have several installation options. Apple maintains their own fork of Git, but it is usually a few versions behind, so we do not recommend installing that.


Git install - Linux

Installing Git on Linux depends on which distro you are running.


Configure git

First check that you have git installed:

$ git --version

Now configure git with

  • git config (local, global, system)

You should at least set your global name and email (just once):

$ git config --global user.name "Your Name"
$ git config --global user.email "yourname@example.com" 

Configure git - continued

Setting the editor (once) is also a good idea:

$ git config --global core.editor <editor>

Choices for editor could be:

  • nano
  • vim
  • emacs

Test your Git installation

Create an example folder and change to that, then create a file test.txt. On Linux you would do this:

$ mkdir <mydir> 
$ cd <mydir>
$ touch test.txt

Now initialize a repository and stage the new file:

$ git init
Initialized empty Git repository in /home/bbrydsoe/test-git/.git/
$ git add test.txt

Now commit the change. The editor which you configured earlier should open. Add an example commit message:

$ git commit test.txt 
[master (root-commit) ff8b6f6] Test of git
 1 file changed, 0 insertions(+), 0 deletions(-)
 create mode 100644 test.txt

Test your Git installation - continued

Now let us look at the log:

$ git log
commit ff8b6f699d98c72d5cffc64d65a1c618b976b45a (HEAD -> master)
Author: Birgitte Brydsö <bbrydsoe@cs.umu.se>
Date:   Thu Sep 17 13:53:59 2020 +0200

    Test of git

When you do git log, you should see something like the above, but with name, email, and commit message different. If that is the case, your Git should be configured correctly.


Download the course materials

For the individual hands-on part of the course, we have created some course materials which you will download from the course website: https://www.hpc2n.umu.se/events/courses/git-fall-2020

  • Please go to the terminal window where you have downloaded and set up Git.
  • Change the directory to wherever you wish to have the course material.
  • Copy/fetch the tarball you downloaded there
  • Unpack with tar zxvf <tarball>

Web based Git repositories

There are several web based Git repository. Some of the more popular ones are:

  • GitHub
  • GitLab
  • Bitbucket

We are going to use GitHub for the part of the hands-on where you will be working together in groups.

Please go to

and sign up for an account.


Editor, using

Vim

  • You may need to install it first. (sudo apt-get install vim)
  • Start with vim <filename> where the file does not need to exist before. You open a new file for editing.
  • Type i to enter 'insert' mode to be able to write in the editor.
  • Use ESC to go to 'command' mode and then :wq to save and exit the editor.
  • When you are in 'command' mode, typing dd will delete the whole line your cursor is on.

Nano

  • Start with nano <filename> where the file does not need to exist before. You open a new file for editing.
  • Ctrl-x will exit the editor, asking first if you want to save it.
Select a repo