
# Git and GitHub
## Computational workshop on version control
Diego Alonso Álvarez and Sandra Álvarez Carretero
---
## Tips and instructions
1. Code along - you will learn more! :computer:
2. Ask questions - any time! :question:
3. Follow on the resources (see next page) :books:
---
## Resources
- [Fundamentals of Git/GitHub](https://imperialcollegelondon.github.io/introductory_grad_school_git_course/)
- [Further Git/GitHub for collaboration](https://imperialcollegelondon.github.io/intermediate_grad_school_git_course/)
- [Referencing and citing content](https://docs.github.com/en/repositories/archiving-a-github-repository/referencing-and-citing-content)
---
## Outline
- What is version control and why does it matter?
- The publication workflow
- Fundamentals of `git`
- Sharing code/data in GitHub
- Make your work citable
- Other applications using GitHub
---
## What is version control and why does it matter?
----
<!-- .slide: style="text-align: left;"> -->
### What is version control?
- A system for managing your work (not necessarily just code) which records snapshots of the current state of a set of files
- Provides a historical record for your project
- Reports “diffs” that describe the file changes between snapshots
----
<!-- .slide: style="text-align: left;"> -->
### What can go wrong without version control?
| A library | Some code that uses it |
|-----------|------------------------|
| mylib-1.2.4_18.tgz | code_CP_10.8.07.tgz |
| mylib-1.2.4_27.tgz | code_CP_17.5.07.tgz |
| mylib-1.2.4_29.tgz | code_CP_23.8.07_final.tgz |
- Lots of manual work to manage these files
- Names are uninformative
- Which versions are compatible with each other?
- Difficult to find changes between versions
----
<!-- .slide: style="text-align: left;"> -->
### What can help version control with?
- Mistakes happen - diagnose and fix them
- Working on different things
- Collaboration
- Reproducibility
---
## The publication workflow
How do we ensure that our code/data is **findable**?
--
[**The FAIR Guiding Principles for scientific data management and stewardship**. Sci Data 3, 160018 (2016)](https://doi.org/10.1038/sdata.2016.18)
--
[**Introducing the FAIR Principles for research software**. Sci Data 9, 622 (2022)](https://doi.org/10.1038/s41597-022-01710-x)
----
`commit` :arrow_forward: `tag` :arrow_forward: Release :arrow_forward: DOI
----
`dkfo344` :arrow_forward: `v0.2.5` :arrow_forward: `v0.2.5` + metadata
:arrow_forward: 10.5281/zenodo.1185315
----
`git` :arrow_forward: `git` :arrow_forward: GitHub :arrow_forward: Zenodo
----
| Concept | Looks like | Handled by |
| -------- | -------- | -------- |
| commit | dkfo344 | git |
| tag | v0.2.5 | git |
| Release | v0.2.5 + metadata | GitHub |
| DOI | 10.5281/zenodo.1185315 | Zenodo |
----
### A case study
[Solcore](https://github.com/qpv-research-group/solcore5)
---
## Fundamentals of `git`
----
<!-- .slide: style="text-align: left;"> -->
### Configuring git
```bash
$ git config --global user.name "FIRST_NAME LAST_NAME"
$ git config --global user.email "email@example.com"
```
- info added to each `commit` (what?)
- accountability (blame!)
- finding who to ask for help
----
### This is what will be going on
<img src="https://imperialcollegelondon.github.io/introductory_grad_school_git_course/fig/git_areas.png" alt="image" width="700" height="auto">
Using `git` is like taking a plane... 🤔
----
<!-- .slide: style="text-align: left;"> -->
### Initialising a repository
Normal directory → version controlled one!
- Running:
```bash
$ git init
```
- Results in:
```output
Initialized empty Git repository in /your/directory/.git
```
Ready to do version control!
----
<!-- .slide: style="text-align: left;"> -->
### Getting information
```bash
$ git status
```
Information of files modified and staged for commit, among other.
```bash
$ git log
$ git log --one-line
```
Information about the history of the repository.
----
<!-- .slide: style="text-align: left;"> -->
### In more detail: `git add`
```bash
$ git add file1 file2...
```
- Adds modified files/folders in your working directory to the **staging area**.
- Only the staging area is committed to history.
- It is an **explicit process**.
- To remove things from the staging area:
```bash
$ git restore --staged file1 file2
```
----
<!-- .slide: style="text-align: left;"> -->
### In more detail: `git commit`
```bash
$ git commit -m "Some short message about the commit."
```
- Adds the staging area to the **history**.
- Contains the changes made since previous point.
- Create a commit id - or commit hash.
- It is an **explicit process**.
- To undo the last commit (safe way):
```bash
$ git reset --soft HEAD^
```
----
### Now this makes sense, right?
<img src="https://imperialcollegelondon.github.io/introductory_grad_school_git_course/fig/git_areas.png" alt="image" width="700" height="auto">
Right?? 🤨
---
---
### Wrap up
- TBC
---
### Thank you!

[www.sruk.org.uk](https://www.sruk.org.uk)
{"title":"Git - computational workshop on version control ","breaks":true,"description":"Version control might be an alien concept for many people, but it is indeed at the heart of reproducible research, fundamental in software development and, ultimately, enables a good practice to keep your data organised. It becomes even more relevant when multiple researchers collaborate on a particular project and it is necessary to know who changed what, when they did that, and, potentially, to be able to easily revert those changes. When developing software (e.g., just a small script to process your data, a more serious application for your research team, or a professional-level program), not using some form of version control is just unthinkable. \n\nAs a continuation of the SRUK/CERU Research Computing Workshop series, we will focus on teaching the basics of the main tool used for version control: Git. In addition, you will learn how to use GitHub, an online repository with which you can collaboratively work on a project while keeping all the benefits of version control.","showTags":"true","image":"https://hackmd.io/_uploads/HkE3wGesa.jpg","contributors":"[{\"id\":\"78c365e8-c501-47e6-ba3b-ef7939b5e127\",\"add\":7483,\"del\":4371}]","slideOptions":"{\"transition\":\"fade\",\"theme\":\"white\",\"parallaxBackgroundImage\":\"https://hackmd.io/_uploads/r1eUkWghp.jpg\"}"}