Git and GitHub

Source code for all tutorials and assignments will be made available in various repositories on GitHub. To download source code you will use Git to clone repositories to your Department Linux user account or to your private computer.

Check if you already have Git installed

Open a terminal, type git --version and press enter.

$ git --version

If git is installed you will something similar to this as a result in the terminal.

git version 1.9.1

If git is not installed you will something similar to this as a result in the terminal.

$ git: command not found

Install Git

If git is not installed on your system, install git by following these instructions.

Example GitHub repository

On the following web page you find an example GitHub repository.

The repository contains the folder sub and the files README.md, one.txt and two.txt. The sub folder contains a single file named third.txt. By clicking on a file, for example the one.txt file, you will see the content of the file.

A small text file.

Cloning a repository

Click on the green button named Clone or download. Now a small pop-up will appear showing the repository URL. To copy the repository URL click on copy-to-clipboard icon to the right of the URL.

From the terminal, navigate to a directory where you want the cloned directory to be created. To clone the example repository, type git followed by a space and paste the repository URL.

$ git clone https://github.com/uu-dsp-os-ospp-2020/module-0-example-repository.git

Press enter to execute the command. Now you should see something similar to this written to the terminal.

Cloning into 'module-0-example-repository'...
remote: Counting objects: 14, done.
remote: Compressing objects: 100% (8/8), done.
remote: Total 14 (delta 1), reused 14 (delta 1), pack-reused 0
Unpacking objects: 100% (14/14), done.
Checking connectivity... done.

Note the first line Cloning into 'module-0-example-repository'.... This tell you that the cloned repository is found in the newly created directory module-0-example-repository within the current working directory.

Investigate the cloned directory

To get an overview of the cloned repository, use the tree command.

$ tree module-0-example-repository

The tree command will print out a tree view showing all files and folders in the module-0-example-repository directory.

module-0-example-repository
├── README.md
├── one.txt
├── sub
│   └── three.txt
└── two.txt

1 directory, 4 files

From the above we see that in the module-0-example-repository we find the files README.md, one.txt and two.txt. In the same directory we also find a sub directory named sub. Within the sub directory we find a single file named three.txt.