2.1. git tutorial/exercices

2.1.1. prerequisite

Connect to your virtual machine (see Pasteur Virtual Machines (VMs) )

2.1.2. cloning an existing repository

Git is a standalone tool. Don't be confuse with github/gitlab that are websites providing a service. For instance, Github is an online website to store git repositories.

Here, we can start by cloning an existing public repository locally

cd $HOME
git clone https://github.com/samtools/samtools.git

You can now go to the directory:

# under linux:
cd samtools

You can play with the content of this repository. There is nothin special here. This is a public repository but you can not push since you do not have the right. Howeve, you can add/commit files locally.

  1. What is the message of the latest commit?

  2. What is the name of the default branch?

  3. What is the url of the repository?

echo "NEW FILE" > new_file.txt
git add new_file.txt
git commit -m "My contribution to samtools"
git push origin develop
  1. What is the message given by git ? What does it means?

2.1.3. Work alone on your private repository

An equivalent to github instance is gitlab. A gitlab instance is hosted on Pasteur's servers. You can create a repository in your gitlab account (using Institut Pasteur login system) on https://gitlab.pasteur.fr. You should first upload an ssh key generated on your VMs. Then, in your account, create a repository called sandbox, then:

git clone git@gitlab.pasteur.fr:<login>/sandbox.git

Once you have cloned the repository, go inside:

# Type
cd sandbox

This is empty of course. Time to add a new file. A good practice is to add a README file. You may add an extension to indicate the syntax of your file. It may be .rst for restructuredText or .md for markdown. Here we use .md.

Note

to know more about restructured text, have a look at this Tutorial . A bit old but should be a good starting point.

Create a file called README.md and add some text inside (anything describing the repository). Once ready, you can add it into your local git repository. The first time you must add it:

git add README.md

To validate the change, you will have to commit your modification:

git commit -m "Added a README file"

Finally, to make sure it is safe, push it online in your gitlab repository:

git push origin master

Check on your https://gitlab.pasteur.fr/<login>/sandbox that the README is there. You may edit the README online. If so, at some point you may want to synchronize your local repository:

git pull origin master

If changes have been made on the server, you should get the changes. Otherwise, well, nothing will happen.

Once synchronised, let us change the README.md locally. Add some new text/info. Check that there are changes with the status command:

git status

you should see that the file has changed indeed. You can commit/push again on the server:

git add README.md
git commit -m "Modified README"
git push origin master
  1. How many commits are there on this git repository (locally and on gitlab)?

  2. How many files are there in the repository?

2.1.4. Working together: Start the project

First have a look at the project we will work on for the rest of the course (Project).

  1. On gitlab, create one repository per group, let's name it reproducibility_project, and add all the members of the group as owners.

  2. All the members of the group can now clone the repository and get the updates (git pull).

  3. Distribute the following tasks between the members of your group:

    1. Write a README.md file

    2. Write 1 bash script to download and extract the input data

    3. Write 1 bash script to run the analyses

  4. Create one branch per task

  5. Merge all the additions to the master branch of the repository

  6. Try to run the scripts

  7. Does it run? If not, why?

2.1.5. Additional information: connect a local repository folder to your empty folder/repository on Github.

Sometimes, you have a nice package on your laptop that you have started from scratch. You suddely realised that you have done lots of work and would like to push it on your github account.

It is possible of course. You can start a local project and later upload it online.

Imagine this local repository called repro. You can initialise it and add a new file as follows:

mkdir repro
cd repro
git init
git add README
git commit README
git push

This is a local repository. Nobody knows about it. Better to push it on external server.

First, you need to create a repository on gitlab. Let us call it repro as well.

Copy the link in the input right beneath the title, it should look something like this: https://gitlab.pasteur.fr/yourlgin/repro.git

This is the gitlab web address where your local folder can be pushed to and linked to at the same time (as if you did a clone).

Go back to your project in the terminal/command line and type this esoteric command:

git remote add origin https://gitlab.pasteur.fr/yourlogin/repo.git

Push your branch to Github:

git push origin master

Go back to the folder/repository screen on GitLab that you just left, and refresh it. You should see the files in the web interface.