2-git
2-git
Systems
29/09/2016
DLR-IDL
2023-2024
Work under Creative Commons BY-SA1 license 2/1
1
http://creativecommons.org/licenses/by-sa/2.0/.
Important notes 3/1
2
http://sl4.org/crocker.html
Sentences one would have preferred not to hear 4/1
3
VCS are not (space) efficient backup systems
Version Control Systems (VCS) 6/1
§ Used for
§ storing files
§ keeping track of changes on those tracked files
§ sharing
§ Each collaborator works on a local copy
§ Synchronization with one (or several) remote server(s)
§ 2 families of VCS
§ centralised (Subversion, CVS, . . . )
§ distributed (Git, Mercurial, Darcs, . . . )
Architecture of a centralised VCS 7/1
WORKING
COPY
synchro
workspace #1
synchro
WORKING CENTRAL
COPY REPOSITORY
workspace #2
synchro
WORKING
COPY
workspace #3
Architecture of a distributed VCS 8/1
REPOSITORY synchro
synchro REPOSITORY
WORKING
COPY synchro synchro
workspace #1
REPOSITORY REPOSITORY
synchro synchro
WORKING WORKING
COPY COPY
workspace #2 workspace #3
Focus on a specific VCS: Git 9/1
Why Git?
§ very popular
§ many platforms provide services built on Git (Bitbucket, Gitlab,
GitHub)
§ a bit less intuitive than other VCS for beginners, therefore if
you are able to use Git, you will be able to use other VCS
§ . . . and because we had to choose a tool
Git architecture and vocabulary 10 / 1
REMOTE
REPOSITORY
Workspace
Gitspace
Repository
Repository
Diving into Git core 11 / 1
Repository
CV = current version
CV
Repository
Diving into Git core 11 / 1
Repository
WD = working directory
WD CV
Repository
.tex
.java
.ml
Diving into Git core 11 / 1
Repository
WD CV
Repository
.tex
‰
.java
.txt
.ml
Diving into Git core 11 / 1
Repository
SA = staging area SA
add
rm
WD CV
Repository
.tex
‰
.java
.txt
.ml
Diving into Git core 11 / 1
Repository
SA
add
rm
WD CV
Repository
.tex
.java
.txt
Diving into Git core 11 / 1
Repository
index
SA
.git
.pdf
config
.java
config
.txt
Diving into Git core 11 / 1
Repository
index
SA
commit .git
add/rm
push
File system HEAD
WD CV fetch/
Repository clone/
objects/, refs/ pull
.tex
.pdf
config
.java
config
.txt
checkout/merge
Structure of a versioned project with Git 12 / 1
jcbach@minitel2>dlr-idl$ls -la
drwxr-xr-x 17 jcbach jcbach 4096 Sep 18 09:07 .
drwxr-xr-x 212 jcbach jcbach 12288 Aug 31 17:11 ..
drwxr-xr-x 7 jcbach jcbach 4096 Sep 18 10:43 .git
-rw-r--r-- 1 jcbach jcbach 132 Jun 3 2020 .gitignore
-rw-r--r-- 1 jcbach jcbach 200 Jan 16 2019 .project
-rw-r--r-- 1 jcbach jcbach 308 Mar 11 2019 Makefile.recur
-rw-r--r-- 1 jcbach jcbach 832 Mar 11 2019 Makefile.rules
-rw-r--r-- 1 jcbach jcbach 3936 Sep 9 2020 README
drwxr-xr-x 4 jcbach jcbach 4096 Sep 18 10:48 adm
drwxr-xr-x 2 jcbach jcbach 4096 Oct 14 2019 agile
drwxr-xr-x 6 jcbach jcbach 4096 Nov 14 2022 build
drwxr-xr-x 3 jcbach jcbach 4096 Oct 18 2022 ci
-rw-r--r-- 1 jcbach jcbach 1496 Jan 23 2019 custom.sty
-rw-r--r-- 1 jcbach users 17 Aug 23 15:52 date.tex
drwxr-xr-x 12 jcbach jcbach 4096 Sep 30 2022 devenv
drwxr-xr-x 3 jcbach jcbach 4096 Aug 11 2020 exam
drwxr-xr-x 3 jcbach jcbach 4096 Sep 18 10:31 introduction
drwxr-xr-x 2 jcbach jcbach 4096 Sep 5 15:30 licence
drwxr-xr-x 2 jcbach jcbach 4096 Sep 26 2019 notes
drwxr-xr-x 2 jcbach jcbach 4096 Oct 24 2018 poly
drwxr-xr-x 2 jcbach jcbach 4096 Sep 10 2020 presentation
drwxr-xr-x 4 jcbach jcbach 4096 Sep 18 10:46 projet
-rw-r--r-- 1 jcbach jcbach 618 Nov 7 2018 ref.bib
drwxr-xr-x 5 jcbach jcbach 4096 Oct 18 2022 test
.git structure 13 / 1
jcbach@minitel2>.git$ls -la
drwxr-xr-x 7 jcbach jcbach 4096 Sep 18 10:43 .
drwxr-xr-x 17 jcbach jcbach 4096 Sep 18 09:07 ..
-rw-r--r-- 1 jcbach jcbach 20 Sep 18 10:43 COMMIT_EDITMSG
-rw-r--r-- 1 jcbach jcbach 109 Jan 18 2023 FETCH_HEAD
-rw-r--r-- 1 jcbach jcbach 23 Aug 9 2019 HEAD
-rw-r--r-- 1 jcbach users 41 Jan 18 2023 ORIG_HEAD
-rw-r--r-- 1 jcbach jcbach 370 Aug 9 2019 config
-rw-r--r-- 1 jcbach jcbach 73 Oct 23 2018 description
-rw-r--r-- 1 jcbach jcbach 17989 Nov 29 2019 gitk.cache
drwxr-xr-x 2 jcbach jcbach 4096 Oct 23 2018 hooks
-rw-r--r-- 1 jcbach users 35901 Sep 18 10:43 index
drwxr-xr-x 2 jcbach jcbach 4096 Oct 23 2018 info
drwxr-xr-x 3 jcbach jcbach 4096 Oct 24 2018 logs
drwxr-xr-x 260 jcbach jcbach 4096 Sep 18 10:43 objects
drwxr-xr-x 5 jcbach jcbach 4096 Mar 12 2019 refs
jcbach@minitel2#10:54:19>.git$
Git by the example 14 / 1
change change
tracked
untracked
change
Example
$> git add file1 file2 file3 ...
add in the index of the staging area
$> git commit -m “add my super new feature”
...
$> git push
push into the remote repository
Checking differences after changes 18 / 1
Diff commands
$> git diff
$> git diff --staged
$> man git-diff will help you
Updating dev environment (fetch) 19 / 1
git fetch
git pull
2. merge 1. fetch
change
HEAD
v0.1 main
A B C
Initial situation
Diverging by the example 25 / 1
HEAD
v0.1 main
A B C
testing
v0.1 main
A B C
testing
HEAD
HEAD
A B C D
HEAD
A B C D
A B C D
hotfix
HEAD
A B C D
hotfix
HEAD
HEAD
A B C D
hotfix
v0.1 testing
A B C D
hotfix
main
v0.1 testing
A B C D
main
HEAD
HEAD
v0.1 testing
A B C D
main
HEAD
v0.1 testing
A B C D F
main
v0.1 testing
A B C D F
main
HEAD
HEAD
A B C D F G
WORKING REMOTE
DIRECTORY REPOSITORY
STAGING LOCAL
git clone
AREA REPOSITORY
git add/rm
git commit
git fetch/pull˚
git checkout/branch/merge
git push
Adopting a workflow 27 / 1
Source: Atlassian
Feature branch workflow 29 / 1
v1 v1.1 main
A B E F I
C D G H
feature1 feature2
Gitflow workflow4 30 / 1
§ strict branching model designed around the project release
§ well-suited for large projects with deadlines (releases)
§ one branch one role, workflow defines their interactions
§ can be combined with feature branch workflow
§ project history = main (the releases) + development branch
Source: Atlassian
4
A famous example:
https://nvie.com/posts/a-successful-git-branching-model/
Forking workflow 31 / 1
Source: Atlassian
5
https://www.gnu.org/philosophy/floss-and-foss.en.html
Workflows: summary 32 / 1
§ Git
§ useful and powerful tool
§ . . . but a tool alone does not solve all problems. It can also create
ones
ñ developers do not only need tools, but also working processes
§ Good practices
§ formalizing the process/workflow
§ coordinating with co-workers
§ testing before sending changes
§ updating before sending a change
§ commiting meaningful changes
§ commiting often
§ adding meaningful messages for commits
§ not commiting generated files
§ short-lived branches
VCS in practice: how to start? 34 / 1
§ By practicing
§ during the next lab session: there are a lot of small exercises to
discover most important Git commands
§ during every lab sessions, even in non-CS context
§ at home
§ VCS
§ https://homes.cs.washington.edu/~mernst/advice/version-control.html
§ https://betterexplained.com/articles/a-visual-guide-to-version-control/
§ https://betterexplained.com/articles/
intro-to-distributed-version-control-illustrated/
§ Git
§ https://git-scm.com/
§ https://git-scm.com/book/en/v2/ (Pro Git book)
§ http://justinhileman.info/article/git-pretty/
§ https://betterexplained.com/articles/aha-moments-when-learning-git/
§ https://rachelcarmena.github.io/2018/12/12/how-to-teach-git.html
§ Subversion: http://svnbook.red-bean.com/
§ Mercurial: https://www.mercurial-scm.org/
Gentle reminder 40 / 1
N Important notes
§ if you do not understand something, please ask your
questions. We cannot answer the questions you do not ask. . .
§ if you disagree with us, please say it (we follow Crocker’s
rules9 )
§ people don’t learn computer science by only reading few
academic slides: practicing is fundamental
9
http://sl4.org/crocker.html