Chapter 3 The use of git
Git is software for collaborative coding, and version control. It can record changes in your code and optionally send them to your collaborators. The nice thing about git projects is that it is possible to host them online, for free. In science, this is important, as you have a backup of important work, that you can freely share.
There are a couple of websites that allow you to host code. The can host your code in a public repository so that everyone can see it, or in a private repo, so that you indicate which users can see it. The owner of the repo always determines the edit rights.
- github
- Github is managed by microsoft, they offer limited free hosting.
- gitlab
- Gitlab is managed by the gitlab company, they offer limited free hosting.
- codeberg
- An open-souce git repo that allows unlimited hosting of public repos, but for private repos you need to pay.
3.1 The basics of cloning
If you want to use the code stored in a repo, but you don’t need to edit it, this guide is for you. Find your git repository you want to clone. For instance this one: https://gitlab.com/bioinformatics-interest-group/materials/phyloseq-introduction. The first step is to obtain the https clone link:
Then, using cd, you navigate to the folder you want to save the cloned project to:
$ git clone https://gitlab.com/bioinformatics-interest-group/materials/phyloseq-introduction.git
Cloning into 'phyloseq-introduction'...
remote: Enumerating objects: 112, done.
remote: Counting objects: 100% (96/96), done.
remote: Compressing objects: 100% (75/75), done.
remote: Total 112 (delta 29), reused 54 (delta 18), pack-reused 16 (from 1)
Receiving objects: 100% (112/112), 3.61 MiB | 1.78 MiB/s, done.
Resolving deltas: 100% (31/31), done.
Now you can cd into phyloseq-introduction and you are done! After cloning a repo, you can see if there is documentation by typing cat README*. This will open the help file. For this example it will print this:
# notebook
Multi os notebook template with pixi.
## Usage
Open your command shell, clone this repository and enter this folder. Type:
pixi start
This opens the [jupyter notebook](http://localhost:8888/lab/tree/Untitled.ipynb). If you do not have pixi installed, follow the instructions [here](https://prefix.dev/docs/pixi/overview#installation).
3.2 The most important parts
Git is a program that maintains a local change log of files (the local repository), and is able to synchronise this with a remote server (the remote repository). When you create or edit files, this is not automatically updated, you have to accept the change you make (staging) to move it to the local repository. You can move your changes to the remote repository any time by pushing.
A new workspace is initialised in the current folder by
Now we can make a file
This file is now in the workspace, we can see this by typing git status:
On branch master
No commits yet
Untracked files:
(use "git add <file>..." to include in what will be committed)
file-1
nothing added to commit but untracked files present (use "git add" to track)