Introduction to Git –- Fall 2020
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:
git init
git config
(local, global, system)git add
git commit
When this is done, you will clone the course materials.
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.
brew install git
Installing Git on Linux depends on which distro you are running.
sudo apt install git
(Ubuntu, Debian)sudo dnf install git
(RHEL, CentOS)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"
Setting the editor (once) is also a good idea:
$ git config --global core.editor <editor>
Choices for editor could be:
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
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.
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
tar zxvf <tarball>
There are several web based Git repository. Some of the more popular ones are:
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.
Vim
sudo apt-get install vim
)vim <filename>
where the file does not need to exist before. You open a new file for editing.i
to enter 'insert' mode to be able to write in the editor.ESC
to go to 'command' mode and then :wq
to save and exit the editor.dd
will delete the whole line your cursor is on.Nano
nano <filename>
where the file does not need to exist before. You open a new file for editing.