marp: true title: Version control with git for scientists author: P.Y. Barriat description: https://dev.to/nikolab/complete-list-of-github-markdown-emoji-markup-5aia backgroundImage: url('assets/back.png') _backgroundImage: url('assets/garde.png') footer: 05/05/2022 | Version control with Git _footer: "" paginate: true
git
for scientists ###
think of it as a series of snapshots (commits) of your code
Testing new idea (and easy way to throw them out) :construction:
Multiple version of the code
git
?git
"Always remember your first collaborator is your future self, and your past self doesn't answer emails" Christie Balhai :wink:
git
workflowYour local repository consists of three areas maintained by git
git
checkout a remote repository
create a local working copy of a remote repository
git clone https://gogs.elic.ucl.ac.be/TECLIM/Git_Training.git
add & commit
you can propose changes (add it to the INDEX)
git add <filename>
you can commit these changes (to the HEAD)
git commit -m "Commit message"
git
versioning is a succession of snapshot of your files at key time of their development
each snapshot is called commit which is :
Your changes are now in the HEAD of your local working copy.
push
to send those changes to your remote repository
git push
pull to update your local working directory to the newest commit, to fetch and merge remote changes
git pull
git
diffsequenceDiagram
%%autonumber
participant Workspace
participant INDEX
%%Note right of Workspace: Text in note
Workspace-->INDEX: git diff
INDEX-->HEAD: git diff --cached
Workspace-->HEAD: git diff HEAD
git
undoIn case you did something wrong (which for sure never happens :wink:)
sequenceDiagram
%%autonumber
participant Workspace
participant INDEX
Note over Workspace,INDEX: wrong modification of a file <br/>in your workspace
INDEX->>Workspace: git checkout -- file
%%HEAD-->Workspace: .<br/>
Note over Workspace,HEAD: wrong modification of a file <br/>that you put in your index
HEAD->>INDEX: git reset HEAD file
INDEX->>Workspace: git checkout -- file
How commonly do programmers use Git GUIs instead of the command line ?
Use programs like SourceTree
or TortoiseGit
But, to be familiar with Git, try the command line
clone, push/pull, merge, rebase, log, tag, format-patch/am, bisect, blame, etc
First, configure your environment (just once) :construction:
on your laptop, on your ELIC account, etc
git config --global user.name "Your Name"
git config --global user.email "foo@bar.be"
git config --global color.ui auto
git config --global core.editor "vim"
git config --list
Now, clone https://gogs.elic.ucl.ac.be/TECLIM/Git_Training.git
Theses are very simple exercices to learn to manipulate git. In each folder, simply run
./create.sh
and follow the guide :sunglasses:
git
branchesgit commit
git checkout -b newbranch
git checkout newbranch
git commit
git commit
git checkout master
git commit
git commit
default branch: master
graph LR;
A[fffc93b] -->|commit| B(fc7f81f)
B -->|commit| D(6fd1a5a)
D -->|commit| E[newbranch <br/>187e6ab ]
B ---->|commit| Z(6ff4c2e)
Z -->|commit| Y[master <br/>c0f502f ]
git checkout -b newbranch
git checkout newbranch
git branch -d newbranch
git branch
branch allow to have short/long term parallel development
the interest of branch is that you can merge them
include in one (branch) file the modification done somewhere else
git merge bx
git branch -d bx
git commit
graph LR;
A(fffc93b<br/>b_x) -->E[187e6ab<br/>b_x merged <br/>in b_y]
D[6fd1a5a<br/>b_y] -->E
E -->|commit| Y[c0f502f<br/>b_y ]
git
& GitHub
?git
is the version control system service
git runs local if you don't use GitHub
GitHub
is the hosting service : website
on which you can publish (push) your git repositories and collaborate with other people
Github
GitLab
vs GitHub
vs othersGitLab
is an alternative to GitHub
GitLab
is free for unlimited private projects.GitHub
doesn't provide private projects for free
And for ELIC, Gogs
does the job: https://gogs.elic.ucl.ac.be/
git
good for ?Backup, reproducibility
Backup, reproducibility, collaboration
git
conflict :boom:Backup, reproducibility, collaboration, transparency
sequenceDiagram
autonumber
participant Workspace
participant INDEX
participant HEAD
participant Remote Repository
Remote Repository->>HEAD: clone
HEAD->>Workspace: checkout
%%Note over Workspace,Remote Repository: "clone" = clone + checkout
Workspace->>INDEX: add
INDEX->>HEAD: commit
Remote Repository->>HEAD: fetch
HEAD->>Workspace: merge
Remote Repository->>Workspace: pull
%%Note over Workspace,Remote Repository: pull = fetch + merge
HEAD->>Remote Repository: push
git
more complicated but the standard :smiley: