SlideShare une entreprise Scribd logo
1  sur  231
lundi 13 mars 2023
GIT TRAINING - Advanced
Thierry GAYET
 The purpose of this training will be to:
 Reminder on git commands
 Devops / devsecops
 Gitlab
 Advanced usage of GIT
 CI and CD
Have a good training 
GOAL
2
scan me
REQUIREMENTS
3
 After the two first modules of the git training, we will continue step
by step in command line for the nerds/geeks or using a graphical tool
such as Visual code studio from Microsoft that can be run on
gnu/linux, Ms Windows or Mac OS X.
 We will use this gitlab project :
https://gitlab.enensys.com/training/git/first-project
 You must have an access to gitlab (and your public ssh (rsa) key
declared : ~/.ssh/id_rsa.pub)
GIT / PURPOSE
4
❑ WINDOWS :
❑ https://gitforwindows.org/
❑ WSL / Ubuntu 22.04 LTS (then see above GNU/Linux)
https://linuxconfig.org/ubuntu-22-04-on-wsl-windows-subsystem-for-linux
❑ MAC OS X :
❑ https://sourceforge.net/projects/git-osx-installer/files/git-2.23.0-intel-
universal-mavericks.dmg/download?use_mirror=autoselect
❑ (homebrew) brew install git + brew install git-gui
❑ (MacPort) sudo port install git
❑ Dmg : https://sourceforge.net/projects/git-osx-installer/
❑ GNU/LINUX :
❑ sudo apt-get install git-all gitg gitk git-man git-doc git-gui git-flow git-svn
❑ dnf install git-all
GIT / INSTALL
5
GIT / INSTALL (LFS)
6
❑ WINDOWS :
❑ GIT-LFS : https://git-lfs.com/
https://linuxconfig.org/ubuntu-22-04-on-wsl-windows-subsystem-for-linux
❑ MAC OS X :
❑ (homebrew) brew install git-lfs
❑ (MacPort) sudo port install git-lfs
❑ GNU/LINUX :
❑ sudo apt-get git-lfs
❑ dnf install git-lfs
GIT / INSTALL (VSCODE)
7
• https://code.visualstudio.com/
• https://vscodium.com/
 Visual Studio Code (aka VSCODE) :
 Recommended Visual studio code
extension:
 Git graph
 Git Blame
 Git (Submodule) Assistant
 Git LFS File Locking UI
 gitlab-ci-validator
 …
8
GIT / CONFIG
9
GIT / CONFIG
Git
10
GIT / CONFIG
Gitlab
11
GIT / CONFIG
Gitlab ci
12
Git ignore
GIT / CONFIG
13
GIT / CONFIG
C++
14
GIT / CONFIG
Python3
15
GIT / CONFIG
Vhdl
16
GIT / CONFIG
dev(sec)ops /
Kubernetes
17
GIT / CONFIG
dev(sec)ops /
K8s charts
helm
18
GIT / CONFIG
CMAKE
19
REACT /
REACTJS
GIT / CONFIG
20
GIT / CONFIG
Php
21
GIT / CONFIG
Packer
22
Terraform
GIT / CONFIG
23
GIT / CONFIG
Docker
24
GIT / CONFIG
Makefile
25
GIT / CONFIG
Ansible
26
GIT / CONFIG
Yocto
Visual Studio Code
27
GIT / PURPOSE (VSCODE)
28
 1. The menu bar
 2. VSCode Sidebar
 3. VSCode Explorer
 4. Debug Console/Terminal
 5. Document Display/Editor
GIT / PURPOSE (VSCODE)
29
30
GIT / PURPOSE (VSCODE)
 VSCODE general usage :
 https://code.visualstudio.com/docs
 https://code.visualstudio.com/docs/terminal/basics
 https://code.visualstudio.com/docs/editor/debugging
 https://code.visualstudio.com/docs/languages/cpp
 https://code.visualstudio.com/docs/languages/python
 https://code.visualstudio.com/docs/languages/javascript
 https://code.visualstudio.com/docs/languages/typescript
 https://code.visualstudio.com/docs/languages/php
 https://code.visualstudio.com/docs/languages/json
 https://code.visualstudio.com/docs/sourcecontrol/overview
 https://code.visualstudio.com/docs/cpp/introvideos-cpp
 https://code.visualstudio.com/docs/containers/overview
 https://code.visualstudio.com/docs/devcontainers/containers
 https://www.youtube.com/watch?v=CZzQn2X8Ja8
GIT / PURPOSE (VSCODE)
31
Reminder on git commands
Command line & Visual Studio Code (Vscode)
32
33
GIT / PURPOSE
https://gitlab.enensys.com/training/git/first-project
git protocol over ssh
https protocol
Config
 Customize your git settings :
$ git config --global user.name "John Doe"
$ git config --global user.email john.doe@enensys.com
$ git config --global color.ui auto
$ git config --global core.editor "nano"
 Update your ~/.gitconfig file :
[diff]
tool = default-difftool
[difftool "default-difftool"]
cmd = code --wait --diff $LOCAL $REMOTE
[merge]
tool = code
[mergetool "code"]
cmd = code --wait --merge $REMOTE $LOCAL $BASE $MERGED
GIT / CONFIG
35
 Check your local git setting :
~/Workspaces/training/fpga (main)$ git config --list --show-origin
file:/etc/gitconfig filter.lfs.clean=git-lfs clean -- %f
file:/etc/gitconfig filter.lfs.smudge=git-lfs smudge -- %f
file:/etc/gitconfig filter.lfs.process=git-lfs filter-process
file:/etc/gitconfig filter.lfs.required=true
file:/home/linux/.gitconfig user.name=Thierry GAYET
file:/home/linux/.gitconfig user.email=Thierry.Gayet@enensys.com
file:/home/linux/.gitconfig core.editor=nano
file:/home/linux/.gitconfig color.branch=auto
file:/home/linux/.gitconfig color.status=auto
file:/home/linux/.gitconfig color.diff=auto
file:/home/linux/.gitconfig color.interactive=auto
file:/home/linux/.gitconfig alias.co=checkout
file:/home/linux/.gitconfig alias.ci=commit
file:/home/linux/.gitconfig alias.br=branch
file:/home/linux/.gitconfig alias.st=status
file:/home/linux/.gitconfig alias.ls=log --oneline --decorate
file:/home/linux/.gitconfig alias.lsa=log --oneline --decorate --all
(…)
36
GIT / CONFIG
You can update / customie your git config
 Upgrade your ~/.bashrc usefull for all commands :
(...)
parse_git_branch() {
git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* (.*)/(1)/’
}
export PS1="u@h [e[32m]w [e[91m]$(parse_git_branch)[e[00m]$ "
(...)
 It will colorize the prompt command line and display the name of the git
repo and the branch’s name :
linux@des126 ~/Workspaces/training/first-project (feature/ttsp-1234/my-first-
files)$
GIT / CONFIG
37
 You can add/change the git user in the Extension Git Graph easily.
 Go to the Extensions tab and install Git Graph.
 Go to the Source Control tab
 Click on the View Git Graph
 Click on the Repository Settings
 In the User Details section, click
Edit and change the Git Username
and Email.
38
GIT / CONFIG
 Several videos on VS CODE and GIT :
 https://code.visualstudio.com/docs/sourcecontrol/overview
 https://www.youtube.com/watch?v=i_23KUAEtUM&embeds_euri=https%3A
%2F%2Fcode.visualstudio.com%2F&feature=emb_imp_woyt
 https://www.youtube.com/watch?v=E6ADS2k8oNQ&embeds_euri=https%3A
%2F%2Fcode.visualstudio.com%2F&feature=emb_imp_woyt
 https://www.youtube.com/watch?v=b9LTz6joMf8&embeds_euri=https%3A%
2F%2Fcode.visualstudio.com%2F&feature=emb_imp_woyt
 https://www.youtube.com/watch?v=HosPml1qkrg&embeds_euri=https%3A
%2F%2Fcode.visualstudio.com%2F&feature=emb_imp_woyt
39
GIT / CONFIG
40
GIT / CONFIG
41
GIT / CONFIG
42
GIT / CONFIG
43
GIT / CONFIG
44
GIT / CONFIG
45
GIT / CONFIG
46
GIT / CONFIG
47
GIT / CONFIG
Clone
GIT / CLONE
49
 Clone your GIT repo :
$ mkdir –p ~/Workspace && cd ~/Workspace
$ git clone git@gitlab.enensys.com:training/git/first-project.git
(Needs to have uploaded his ssh key (~/.ssh/id_rsa.pub) in his gitlab profile)
Cloning into 'test’...
remote: Enumerating objects: 3, done.
remote: Counting objects: 100% (3/3), done.
remote: Compressing objects: 100% (2/2), done.
remote: Total 3 (delta 0), reused 0 (delta 0), pack-reused 0
Receiving objects: 100% (3/3), done.
OR
$ git clone https://gitlab.enensys.com/training/git/first-project.git
Cloning into 'first-project’...
Username for 'https://gitlab.enensys.com': gayett
Password for 'https://gayett@gitlab.enensys.com’:
remote: Enumerating objects: 3, done.
remote: Counting objects: 100% (3/3), done.
remote: Compressing objects: 100% (2/2), done.
remote: Total 3 (delta 0), reused 0 (delta 0), pack-reused 0
Receiving objects: 100% (3/3), done.
 By default a git repo take the repo from the server but can be change
if we provide a name at the clone time :
$ git clone git@gitlab.enensys.com:training/git/first-project.git first-projet-2
Cloning into ‘first-project-2’...
remote: Enumerating objects: 3, done.
remote: Counting objects: 100% (3/3), done.
remote: Compressing objects: 100% (2/2), done.
remote: Total 3 (delta 0), reused 0 (delta 0), pack-reused 0
Receiving objects: 100% (3/3), done.
50
GIT / CLONE
 We can now check branches :
$ cd first-project/
~/Workspaces/first-project (main)$
~/Workspaces/first-project (main)$ git branch
* main
~/Workspaces/first-project (main)$ git branch –a
* main
remotes/origin/HEAD -> origin/main
remotes/origin/main
GIT / CLONE
51
Local branch(es)
Local and remotes branches
Name of the current branch : main
Name of the git repo just cloned
 Now, using visual
code :
GIT / CLONE
52
Select that we want to clone
a git repo.
53
GIT / CLONE
Just copy/paste the
url of the git repo to
clone
Valid by
clicking on
the « Clone
from url »
54
GIT / CLONE
VS code will ask you to
choose a folder where
you want to clone your
git repo :
Confirm by clicking
on that button
 Finally, we can open the repo just cloned :
 We can also confirm that we trust the git repo :
55
GIT / CLONE
Say that we want to open the source
of the git repo just cloned
Check that this repo is trusted
And validate by clicking on the button
"Yes, i trust the authors ...."
56
GIT / CLONE
The project is
now available
using visual
code.
This is an
empty repo so
this is normal if
there is nothing
inside !
Default’s branch
(main)
57
GIT / CLONE
Local branch
Remote branch
(on the gitlab server)
Inspect a repo
 We can dump the repo’s config :
~/Workspaces/fpga (main)$ cat .git/config
[core]
repositoryformatversion = 0
filemode = true
bare = false
logallrefupdates = true
[remote "origin"]
url = git@gitlab.enensys.com:tm-terrestrial/satcaster2/fpga.git
fetch = +refs/heads/*:refs/remotes/origin/*
[branch "main"]
remote = origin
merge = refs/heads/main
[gitg]
mainline = ""
59
GIT / INSPECT
 Check the remotes :
~/Workspaces/fpga (main)$ git remote –v
origin git@gitlab.enensys.com:tm-terrestrial/satcaster2/fpga.git (fetch)
origin git@gitlab.enensys.com:tm-terrestrial/satcaster2/fpga.git (push)
60
GIT / INSPECT
 Check the local and remote branches :
~/Workspaces/fpga (main)$ git branch –a
* main
remotes/origin/HEAD -> origin/main
remotes/origin/main
~/Workspaces/fpga (main)$ git log
commit 4f9d0d3a053cc81cd74980276cccb6b045cf5529 (HEAD -> main, origin/main, origin/HEAD)
Author: Olivier PIEDCOQ olivier.piedcoq@enensys.com
Date: Wed Mar 8 16:17:08 2023 +0100
remove satcasterII.rbf ; only satcasterII.rbf.gz in git
commit 9e172333d2d25873fa4b787e58db8394c1f7db2d
Author: Olivier PIEDCOQ <olivier.piedcoq@enensys.com>Date: Tue Jan 31 09:32:17 2023 +0000
use last revision of common_regs & giga_ctrl
commit 0a78c28487f4e7ad0f80d105f96676bae2e57b0a
Author: Olivier PIEDCOQ olivier.piedcoq@enensys.com
(…)
61
GIT / INSPECT
62
GIT / INSPECT
 Inspect the previous commits :
~/Workspaces/fpga (main)$ git log
commit 4f9d0d3a053cc81cd74980276cccb6b045cf5529 (HEAD -> main, origin/main, origin/HEAD)
Author: Olivier PIEDCOQ olivier.piedcoq@enensys.com
Date: Wed Mar 8 16:17:08 2023 +0100
remove satcasterII.rbf ; only satcasterII.rbf.gz in git
commit 9e172333d2d25873fa4b787e58db8394c1f7db2d
Author: Olivier PIEDCOQ <olivier.piedcoq@enensys.com>Date: Tue Jan 31 09:32:17 2023 +0000
use last revision of common_regs & giga_ctrl
commit 0a78c28487f4e7ad0f80d105f96676bae2e57b0a
Author: Olivier PIEDCOQ olivier.piedcoq@enensys.com
(…)
~/Workspaces/training/fpga (main)$ git log --oneline --all --decorate --graph
* 4f9d0d3 (HEAD -> main, origin/main, origin/HEAD) remove satcasterII.rbf ; only satcasterII.rbf.gz in git
* 9e17233 use last revision of common_regs & giga_ctrl
* 0a78c28 update .gitignore to ignore .log file
* 9831cd3 remove unused component definition
* abb752f update to quartus 22.2
* b7f7582 update to quartus 22.2
* a081ad3 remove unused dcboard_33_io output (NA in hdm2-sat2 board), remove unused mdio_control(no ip extension card available in hdm2-sat2)
* bfb10e5 update git ignore file
* b14c890 Merge branch 'main' of gitlab.enensys.com:tm-terrestrial/satcaster2/fpga
|
| * 41f9eb2 fix firmware name
* | d171cda regenerate firmware after git migration
|/
* 37d6331 fix migration
* 49c2a35 add common modules checkout script; fix directory structure due to git migration; remove inband configuration module
* 360634b remove unsued pcie_ts_read_arria_10_pkg package fix rtp_mgnt component instantiation
* 786c99e add svn revision & fpga occupation summary
(…)
63
GIT / INSPECT
64
$ gitk
GIT / INSPECT
$ gitg
65
GIT / INSPECT
66
GIT / INSPECT
Using the git graph extension,
we can view the branch, commits,
merges
(see on next slide)
Now with vscode
67
GIT / INSPECT
Using the git
graph extension
68
GIT / INSPECT
Show Git Output
 Clone the « first projet » repo using the
git protocol
 Inspect it
69
GIT / BRANCHES
Create branches for the gitflow
 The goal is to apply the NN6 gitflow that must be apply on all git repo :
 main : the stable branch similar to the production
 integration : the branch used for intermediate integration is the equivalent of
a preproduction
 development : the unstable branch used to merge the developments to be
integrated
71
GIT / BRANCHES
GITFLOW
72
❑ The official GITFLOW to be use is the following one :
main/stable/production
preprod/integration
Development/unstable
HOTFIX / ID-JIRA / DESCRIPTION
BUGFIX / ID-JIRA / DESCRIPTION
FEATURE / ID-JIRA / DESCRIPTION
TAG1 TAG2
rebase
rebase
rebase
Merge
request
Merge
request
Merge
request
Merge
request
MR
Merge
request
Push
+
merge
request
Push
+
merge
request
Push
+
merge
request
73
GITFLOW
Main
(stable’s branch)
Integration’s branch
Develop
(unstable’s branch)
HOTFIX
branch
branch
branch
Push on
the bugfix
branch
BUGFIX
FEATURE
Rebase
branch
branch
Rebase
Push + Merge
Request
Push + Merge
Request
All branches merged into this
integration branch should reflect
what will be described in the final
release note.
RC
9.1.0
RC
9.1.1
HOTFIX
branch
Merge
Request
Merge
Request
Merge
Request
Merge
Request
9.0.0 9.1.1
Merge
Request
Push on
the bugfix
branch
Merge
Request
Merge
Request
CI : linters (gitlab)
Hotfix
release
Official
release
Hotfix
release
If the
hotfix is
clean!
If the
hotfix is
clean!
Jenkins nightly build +
sanity tests
Jenkins build +
focus test on
the hotfix
Jenkins build +
focus test on
the hotfix
Jenkins build + complete tests
Jenkins nightly build +
sanity tests
74
GITFLOW
main
integration
develop
hotfix
bugfix
feature
Push
Merge
request
Create
branch
Create
branch
Create
branch
Create
branch
Create
branch
Rebase
Hotfix
release
Jenkins build +
focus test on
the hotfix
Jenkins nightly
build + sanity
tests
Push
Merge
request
Rebase
Jenkins nightly
build + sanity
tests
CI : linters (gitlab)
Merge
request
Merge
request
Jenkins build + complete tests
9.0.0 9.1.1
Official
release
Merge
request
75
 Create branches (in two time) :
~/Workspaces/first-project (main)$ git branch
* main
~/Workspaces/first-project (main)$ git branch integration
~/Workspaces/first-project (main)$ git branch
integration
* main
~/Workspaces/first-project (main)$ git checkout integration
Switched to branch 'integration’
~/Workspaces/first-project (integration)$ git branch
* integration
main
~/Workspaces/first-project (integration)$ git branch develop
~/Workspaces/first-project (integration)$ git branch
develop
* integration
main
~/Workspaces/first-project (integration)$ git checkout develop
Switched to branch
~/Workspaces/first-project (develop)$ git branch
* develop
integration
main
 Git branch <branch_name>
create a new branch
 Git checkout <branch_name>
switch to an existing branch
GIT / BRANCHES
 Create branches and switch (with the same command) :
~/Workspaces/first-project (main)$ git branch
* main
~/Workspaces/first-project (main)$ git checkout -b integration
Switched to a new branch 'integration’
~/Workspaces/first-project (integration)$ git branch
* integration
main
~/Workspaces/first-project (integration)$ git checkout -b develop
Switched to a new branch 'develop’
~/Workspaces/first-project (develop)$ git branch
* develop
integration
main
76
GIT / BRANCHES
 Git checkout –b <branch_name>
create and switch to the new branch
 After the creation all branches are just local and must be pushed to the remote (called origin by default) :
~/Workspaces/first-project (hotfix/ttsp-1245/Fix-database-problem)$ git branch -a
develop
feature/TTSP-27-37/launch-a-vmaf-analysis
* hotfix/ttsp-1245/Fix-database-problem
integration
main
remotes/origin/HEAD -> origin/main
remotes/origin/main
~/Workspaces/first-project (hotfix/ttsp-1245/Fix-database-problem)$ git checkout integration
Switched to branch 'integration’
~/Workspaces/first-project (integration)$ git push origin integration
Total 0 (delta 0), reused 0 (delta 0), pack-reused 0
remote:
remote: To create a merge request for integration, visit:
remote: https://gitlab.enensys.com/training/git/first-project/-/merge_requests/new?merge_request%5Bsource_branch%5D=integration
remote:
To gitlab.enensys.com:training/git/first-project.git
* [new branch] integration -> integration
77
GIT / BRANCHES
The main’s branch is the default branch juste clone, so we don’t have to create or push it !
78
GIT / BRANCHES
~/Workspaces/first-project (integration)$ git branch -a
develop
feature/TTSP-27-37/launch-a-vmaf-analysis
hotfix/ttsp-1245/Fix-database-problem
* integration
main
remotes/origin/HEAD -> origin/main
remotes/origin/integration
remotes/origin/main
~/Workspaces/first-project (integration)$ git checkout develop
Switched to branch 'develop’
~/Workspaces/first-project (develop)$ git branch
* develop
feature/TTSP-27-37/launch-a-vmaf-analysis
hotfix/ttsp-1245/Fix-database-problem
integration
main
The integration’s branch is now pushed on the remote origin server !
79
GIT / BRANCHES
~/Workspaces/first-project (develop)$ git push origin develop
Total 0 (delta 0), reused 0 (delta 0), pack-reused 0
remote:
remote: To create a merge request for develop, visit:
remote: https://gitlab.enensys.com/training/git/first-project/-/merge_requests/new?merge_request%5Bsource_branch%5D=develop
remote:
To gitlab.enensys.com:training/git/first-project.git
* [new branch] develop -> develop
~/Workspaces/first-project (develop)$ git branch -a
* develop
feature/TTSP-27-37/launch-a-vmaf-analysis
hotfix/ttsp-1245/Fix-database-problem
integration
main
remotes/origin/HEAD -> origin/main
remotes/origin/develop
remotes/origin/integration
remotes/origin/main
The develop’s branch is now pushed on the remote origin server !
80
GIT / BRANCHES
All your branches are well done !
81
GIT / BRANCHES
We can create the
integration’s branch
The default’s
branch is main
Now with vscode
82
GIT / BRANCHES
We are now on
the integration’s
branch
83
GIT / BRANCHES
The branch is
integration
We can create the
integration’s branch
84
GIT / BRANCHES
We are now on
the develop’s
branch
85
GIT / BRANCHES
By clicking on
the branch’s
name it will
display all one
Here is a summary of the branches created localy
We will see how to push them to the gitlab server
86
GIT / BRANCHES
Right click on the branch’s name
87
GIT / BRANCHES
Always avoid push force !
88
GIT / BRANCHES
The linux integration is now on the gitlab server (origin)
89
GIT / BRANCHES
The Intégration branch is now
on Gitlab
 We can also push the develop’s branch as well !
 Create the following branches (from main) :
 main-USERNAME
 integration-USERNAME
 develop-USERNAME
 Push your all your branches to GITLAB (origin)
90
GIT / BRANCHES
 All branches’s name must be in lowercase
 just replace USERNAME by your nn6 one !
Create working branches
(feature/bugfix/hotfix)
 Now that we are on the develop’s branch, we can create feature branch :
~/Workspaces/first-project (develop)$ git branch –a
* develop
integration
main
remotes/origin/HEAD -> origin/main
remotes/origin/main
~/Workspaces/first-project (develop)$ git checkout -b feature/ttsp-2737/launch-a-vmaf-analysis
Switched to a new branch 'feature/ttsp-2737/launch-a-vmaf-analysis’
~/Workspaces/first-project (feature/ttsp-2737/launch-a-vmaf-analysis)$ git branch
develop
* feature/TTSP-27-37/launch-a-vmaf-analysis
integration
main
 The workflow is similar with bugfix  eg: bugfix/ttsp-1245/Fix-a-memory-leak
92
GIT / BRANCHES
 We can create a hotfix branch from the main’s branch :
~/Workspaces/first-project (feature/TTSP-27-37/launch-a-vmaf-analysis)$ git checkout main
Switched to branch 'main'
Your branch is up to date with 'origin/main’.
~/Workspaces/first-project (main)$ git checkout -b hotfix/ttsp-1245/Fix-database-problem
Switched to a new branch 'hotfix/ttsp-1245/Fix-database-problem'
~/Workspaces/first-project (hotfix/ttsp-1245/Fix-database-problem)$ git branch
develop
feature/TTSP-27-37/launch-a-vmaf-analysis
* hotfix/ttsp-1245/Fix-database-problem
integration
main
93
GIT / BRANCHES
94
GIT / BRANCHES
We are on
the develop’s
branch
Select « Create new branch from »
Because we are already on the develop’s
branch this is possible to select « create new
branch’s name (from the current’s one. We
already experiment that way so we will use
another one.
Now with
vscode
FEATURE
/ BUGFIX
95
GIT / BRANCHES
Comfirm that we want
to start from the
develop’s branch
96
GIT / BRANCHES
Now we can fill the right branch’s pattern
feature/id-jira/description
bugfix/id-jira/description
and valid with ENTER
97
The feature
branch’s name
is correct
GIT / BRANCHES
98
GIT / BRANCHES
Comfirm that we want
to start from the
main’s branch
HOTFIX
99
GIT / BRANCHES
Now we can fill the right branch’s pattern
hotfix/id-jira/description
and valid with ENTER
100
GIT / BRANCHES
The hotfix
branch’s name
is correct
 We can also push the feature/bugfix/hotfix branches to gitlab !
 Create one branch (from main-USERNAME) :
 hotfix/ttsp-1234/USERNAME/memory-leak
 Create the two branches (from develop-
USERNAME) :
 feature/ttsp-4567/USERNAME/vmaf-sampling
 bugfix/ttsp-7890/USERNAME/database-issue
 Push your all your branches to GITLAB (origin)
101
GIT / BRANCHES
 All branches’s name must be in lowercase
 just replace USERNAME by your nn6 one !
Files
 Now we will create two files :
 hello.c
#include <stdio.h>
int main()
{
printf("Hello, NN6 !");
return 0;
}
103
GIT / FILES
 And a Makefile :
all:
gcc –c ./hello.c –o ./hello.o
gcc ./hello.o –o ./hello
run:
./hello
clean:
rm –f ./hello.o ./hello
104
GIT / FILES
 First of all, create a working branch for your new feature (from
develop) :
~/Workspaces/first-project (develop)$ git checkout -b feature/ttsp-
1234/my-first-files
Switched to a new branch 'feature/ttsp-1234/my-first-files'
105
GIT / FILES
 We can now add the two files :
~/Workspaces/first-project (feature/ttsp-1234/my-first-files)$ git status
On branch main
Your branch is up to date with 'origin/main'.
Untracked files:
(use "git add <file>..." to include in what will be committed)
Makefile
hello.c
nothing added to commit but untracked files present (use "git add" to track)
~/Workspaces/first-project (feature/ttsp-1234/my-first-files)$ git add Makefile hello.c
~/Workspaces/first-project (feature/ttsp-1234/my-first-files)$ git status
On branch main
Your branch is up to date with 'origin/main'.
Changes to be committed:
(use "git restore --staged <file>..." to unstage)
new file: Makefile
new file: hello.c
106
GIT / FILES
Adding files
 Commit them localy :
~/Workspaces/first-project (feature/ttsp-1234/my-first-files)$ git log
commit a97b5e2610097529801eec5a4798f688ed227e5b (HEAD -> main, origin/main, origin/HEAD, integration, hotfix/ttsp-1245/Fix-database-
problem, feature/TTSP-27-37/launch-a-vmaf-analysis, develop)
Author: Thierry GAYET <thierry.gayet@enensys.com>
Date: Thu Apr 13 09:34:27 2023 +0000
Initial commit
~/Workspaces/first-project (feature/ttsp-1234/my-first-files)$ git commit -m "Add the two files"
[main d8bc333] Add the two files
2 files changed, 16 insertions(+)
create mode 100644 Makefile
create mode 100644 hello.c
~/Workspaces/first-project (feature/ttsp-1234/my-first-files)$ git status
On branch main
Your branch is ahead of 'origin/main' by 1 commit.
(use "git push" to publish your local commits)
nothing to commit, working tree clean
107
GIT / FILES
Commit files
~/Workspaces/first-project (main)$ git log
commit d8bc333b8557ab15cd088f7250ebb1f4da31aaa9 (HEAD -> main)
Author: Thierry GAYET <Thierry.Gayet@enensys.com>
Date: Fri Apr 14 16:36:57 2023 +0200
Add the two files
commit a97b5e2610097529801eec5a4798f688ed227e5b (origin/main, origin/HEAD, integration, hotfix/ttsp-1245/Fix-database-problem,
feature/TTSP-27-37/launch-a-vmaf-analysis, develop)
Author: Thierry GAYET <thierry.gayet@enensys.com>
Date: Thu Apr 13 09:34:27 2023 +0000
Initial commit
~/Workspaces/first-project (main)$ git push origin main
Enumerating objects: 5, done.
Counting objects: 100% (5/5), done.
Delta compression using up to 8 threads
Compressing objects: 100% (4/4), done.
Writing objects: 100% (4/4), 460 bytes | 460.00 KiB/s, done.
Total 4 (delta 0), reused 0 (delta 0), pack-reused 0
To gitlab.enensys.com:training/git/first-project.git
a97b5e2..d8bc333 main -> main 108
GIT / FILES
Push to the gitlab server (aka origin)
~/Workspaces/first-project (feature/ttsp-1234/my-first-files)$ git status
On branch main
Your branch is up to date with 'origin/main'.
nothing to commit, working tree clean
~/Workspaces/first-project (feature/ttsp-1234/my-first-files)$ git rebase main
Successfully rebased and updated refs/heads/feature/ttsp-1234/my-first-files.
OR
~/Workspaces/first-project (feature/ttsp-1234/my-first-files)$ git rebase main feature/ttsp-1234/my-first-files
Current branch feature/ttsp-1234/my-first-files is up to date.
~/Workspaces/training/first-project (feature/ttsp-1234/my-first-files)$ git checkout main
Switched to branch 'main'
Your branch is up to date with 'origin/main’.
~/Workspaces/training/first-project (main)$ git merge feature/ttsp-1234/my-first-files
Already up to date.
~/Workspaces/first-project (main)$ git push origin main
109
GIT / FILES
We need to switch to the main branch !
We resynchronize the main branch wit the current one
We can resynchronize the main branch with the other one given
On the main branch, we merge our feature branch to main
Finaly we push the local main branch to gitlab
110
GIT / FILES
Now with
vscode
111
GIT / FILES
We specify the develop branch and valid with ENTER
112
GIT / FILES
We fill the new branch’s name
and valid with ENTER or cancel with ESCAPE
113
GIT / FILES
The branch is correct
We can add a file hello.c then Makefile by this way
114
GIT / FILES
The two files are well added localy
115
GIT / FILES
hello.c is already added
Makefile is not added yet
We can add it using this icon
A mean Added
116
GIT / FILES
The two files are added
Now we can commit and/or push to the gitlab server
 Then we can create Merge request on GITLAB but we will see that
later.
117
GIT / FILES
 On your develop-USERNAME, add hello.c +
Makefile to the project to the GIT project
 Commit the files
 Push your branch to GITLAB (origin)
118
GIT / FILES
 All branches’s name must be in lowercase
 just replace USERNAME by your nn6 one !
DEV(SEC)OPS
119
 Worldwide, interest and adoption of DevOps is growing rapidly. But what
is DevOps ?
1. DevOps is a set of practices that emphasizes collaboration and
communication between software developers and IT operations
professionals, automating the process of software delivery and
infrastructure changes.
2. The term DevOps was born from the union of “development” and
“operations” whose objective is to promote better communication between
the two teams.
3. DevOps aims to create a culture and environment in which the design,
testing and release of software can be done quickly, frequently and
efficiently. DevOps is not just a methodology, it is a real philosophy of work.
DEVOPS
120
 Benefits of adopting the DevOps approach :
 1. Improved quality of code, products and services (reduced bugs, higher change
success rate, etc.)
 2. Increased efficiency (eg optimization of time spent on activities that create
added value: unprecedented added value for the customer)
 3. Improved time to market
 4. Better alignment between IT and business
 5. Smaller versions delivered very quickly and very frequently
 6. Improved productivity, customer satisfaction, staff satisfaction
 7. Less risk and less backtracking
 8. Long-term cost reduction
DEVOPS
121
DEVOPS / DEFINITION
122
START
LINTERS
AUTO TESTS
BUILD
 The DevSecOps (Development - Security - Operations) approach is an approach that
allows data security to be integrated from the start of a project. The security of these
is considered a prerequisite before starting. The goal is to be able to integrate it into
the entire project life cycle, from development to implementation, using flexible
methods and the DevOps approach.
 Integrated into the DevOps process, DevSecOps allows you to configure security test
automation every time your application, software, website is tested and deployed.
This allows anomalies to be detected and corrected quickly.
 The DevSecOps approach involves thinking about the security of your project's
applications and infrastructures from the design stage. It is also recommended to
automate some tasks regarding data security to avoid slowing down DevOps workflow.
To achieve these goals, it is necessary to start by selecting tools that can ensure the
continuous integration of security issues, for example, with a common integrated
development environment that provides security functionality. However, for DevOps
security to be effective, it requires more than new tools. It is necessary to culturally
integrate the new security procedures within your teams so that this is implemented
and applied as quickly as possible.
DEVSECOPS / DEFINITION
123
 Benefits of adopting the DevSecOps approach :
1. Security must be integrated from the start of a project (data protection by design) and into the development and
implementation processes. In the same way that DevOps automates application deployments, DevSecOps automates
security testing. These must be carried out immediately after the first delivery of your project (application, software, etc.).
This applies to development, demo, test and pre-production environments. Automated monitoring of the results of these
tests will alert relevant teams to vulnerabilities in real time long before the final product reaches the production environment.
This process enables early detection of data security gaps and gaps. This allows you to react quickly so that you can deploy
a final product that will have far fewer privacy and data security issues.
2. Develop a culture of safety among your employees
3. For the DevSecOps approach to be effective, close cooperation is required between Dev Ops, Operations teams, IT and
project stakeholders. Therefore, in order to develop a culture of safety, it is necessary to create an atmosphere of trust
between the groups.
4. In order for everyone to feel involved in the cooperation, training and security awareness sessions can be planned. The CIO
plays an important role because he has an overview of the project and the teams and allows him to play a transverse role,
necessary for the proper functioning of the project.
5. Use of computer security automation tools
6. An effective DevSecOps process is only possible with the right tools. The use of a vulnerability scanner, for example, allows
automatic analysis of web applications. This type of tool can be integrated very well into your current operational processes
DEVSECOPS
124
DEVSECOPS
125
DEVSECOPS
126
DEVSECOPS
127
Gitlab
128
Introduction
 The interface of GitLab remains very similar to that of GitHub. However,
GitLab offers options that are less practical :
 Project management
 Planning / prioritization
 Build
 Software testing
 Application Security
 Configuration Management
 Monitoring
 Continuous integration and deployment, etc.
GITLAB / INTRODUCTION
130
 Structure of GITLAB :
GITLAB /
131
GIT REPO
Package registry
.deb
.rpm
.tar.gz
Docker registry
Infrastructure registry
(for the deploy using Terraform)
GITLAB
https://gitlab.enensys.com/help/user/packag
es/package_registry/index
https://gitlab.enensys.com/help/user/infrast
ructure/index
git / ssh
https
RUNNERS
CI
.gitlabci.yml
GITLAB / ARCHITECTURE
132
 GitLab and Docker
 Free software Docker launches applications in software containers. For the
use of GitLab, its integration makes it possible to automate certain
functionalities when sending your source code.
 For example, it can perform unit tests, send notifications and install "npm
install" type dependencies.
 GitLab also has a GitLab agent for the Kubernetes container orchestrator,
which allows it to apply its CI/CD pipeline to Kubernetes clusters.
GITLAB / DOCKER
133
 GitLab API
 To benefit from the GitLab API documentation, the company offers online
documentation, as well as a search engine to find answers to more specific
technical questions.
 https://docs.gitlab.com/ee/api/
 https://docs.gitlab.com/search/
 External build require API TOKENS !
GITLAB / API
134
 What is GitLab CI?
 GitLab CI/CD is a GitLab tool designed to manage the continuous
integration and deployment of application code and revisions. GitLab CI/CD
goes through the configuration of a file called .gitlab-ci.yml placed in the
root directory. A file that generates a pipeline executing code changes
within the code repository.
GITLAB / CI
135
 GIT WORKFLOW :
136
REMOTE / ORIGIN
GITLAB’S SERVER
LOCAL
YOUR COMPUTER
+ fetch
GITLAB
137
CODE
ADD
+
COMMIT
LOCAL
CI :
LINTERS
REMOTE / ORIGIN
GITLAB
BUILD TEST TAG DEPLOY
PUSH
main (stable)
integration
develop (instable)
 What is a GitLab Runner?
 Gitlab-runner is the application for running
tasks in a GitLab CI/CD pipeline.
 If installing Gitlab-runner locally, it is recommended
to deploy it on a separate machine from the one
hosting the GitLab instance, both for performance
and security reasons.
 Each must be equipped with its own software
stack: OS, Kubernetes, Docker...
GITLAB / RUNNER
138
 Guest :
GITLAB / PERMISSIONS
139
 Reporter :
140
GITLAB / PERMISSIONS
 Developer :
141
GITLAB / PERMISSIONS
 Some of the specific actions that the Developer permission role is able to take
include:
 Create new branches
 Remove certain branches
 Lock merge request threads
 Create, manage, accept, and label merge requests
 Create or update a commit status
 Delete images from a container registry
 Add tags to the issue tracker
 Create and edit Wiki pages
 Apply code change suggestions
 Create, edit, and delete project milestones
142
GITLAB / PERMISSIONS
 Maintainer :
143
GITLAB / PERMISSIONS
 The Maintainer role can take all the actions allowed in the Developer role, as
well as actions including:
 Add new members to the project
 Determine write protection status for branches
 Determine write protection status for pushes to branches
 Edit the settings for the project
 Configure project hooks
 Manage job triggers
 Manage runners
 Manage environmental variables
 Manage domains
 Manage certificates
 Manage and delete GitLab Pages
 Edit comments that any user posts
 Delete Wiki pages 144
GITLAB / PERMISSIONS
 Owner :
145
GITLAB / PERMISSIONS
https://nira.com/gitlab-permissions/#:~:text=The%20Owner%20role%20is%20the,to%20nearly%20all%20projects'%20actions.
Create a new project
 To create a new git repo, we need to be in the right group
 Each git repo have its own :
 Docker registry
 Package registry
 Infrastructure registry
 CI / CD pipeline (.gitlabci.yml file)
 WIKI
 Settings
147
GITLAB / CREATE
148
GITLAB / CREATE
GITLAB / CREATE
149
GITLAB / CREATE
150
Name of the new GIT repo
NN6 base URL
Option for the repo
Visibility
Namespace Name of the repo
Validate with create project
 For the new repo :
Base URL : https://gitlab.enensys.com/
Namespace : training/gitlab
Project’s name : my-second-project
Final GIT url : GIT git@gitlab.enensys.com:training/gitlab/my-second-project.git
Final https url : https://gitlab.enensys.com/training/gitlab/my-second-project.git
 When we have always the same namespace, we can set/use groups :
151
GITLAB / CREATE
152
GITLAB / CREATE
 If you don’t have access to some groups, you can send an email to helpdesk@enensys.com
GITLAB /CREATE
153
 After few
seconds, Gitlab
has create the GIT
repo
GITLAB / CREATE
154
Identity
Last commit message / SHA1
URLs for the clone
Links to open in VS code
or others IDE
First file
Quick shortcuts
Default’s branch
Summary
155
 Create a private git repo called « myrepo-
USERNAME » inside the traning/gitlab
namespace
(https://gitlab.enensys.com/training/gitlab)
 Create all the branches according to the
gitflow (using VSCODE and/or GITLAB)
 Check that the default’s branch is main
 Restrict any direct push to main, intégration
and develop
 Add one hello.c and Makefile files
 Add a .gitignore file (filled with
https://www.toptal.com/developers/gitignore)
 Add, commit and push all to GITLAB
 All branches’s name must be in lowercase
 just replace USERNAME by your nn6 one !
GITLAB / CREATE
INSPECT THE PROJECT (LEFT SIDEBAR)
 The following slides will be usefull to customize a new repo but also
an existing one.
 We will see step by step what is to customize…
157
GITLAB / INFO
GITLAB / INFO
158
GITLAB / INFO
159
GITLAB / INFO
160
People that have right to the git repo
Role
GITLAB / REPO.
161
The following files or directories can only be modified by the user who locked them.
To see what's changed or create a merge request, choose a branch or tag (like main ), or enter a commit (like 4eedf23 ).
Changes are shown as if the source revision was being merged into the target revision.
Display a graph of the commits by branch
Stats of commits by users
Create/List/Delete Tags for the releases
List of the files per branch
List of the commits per branch
Create/List/Branches
GITLAB / REPO. / GRAPH
162
 Example ot GIT repository with no branches (very flat) !
163
GITLAB / REPO. / GRAPH
 Example of GIT repository with branches
GITLAB / REPO. / BRANCHES
164
GITLAB / REPO. / BRANCHES
165
GITLAB / REPO. / BRANCHES
166
Default’s branch
GITLAB / ISSUES
167
Not use at NN6 ; similar to JIRA as a bug tracker !
 Merge request can be used for :
 Code review
 Share code between team members
 Validate modification from one branch to another one
 feature or bugfix branches  develop’s branch
 develop’s branch  integration’s branch
 integration’s branch  main’s branch
Only if the hotfix is cleaned :
 hotfix’s branch  integration’s branch
 Integration’s branch to develop’s branch
 MR workflow :
168
GITLAB / Merge Request
Creation Validation Merge Destroy source’s branch
GITLAB / Merge Request
169
Workflow :
 A developer has finished developing a feature / a bugfix and asks to merge his code to the develop branch
 He makes a merge request to one or more of his colleagues
 One of his colleagues makes a remark to him that he must take into account
 After modification resulting from the remark, a new push is carried out with the same Merge Request
 This time, the MR is validated
 Then, the code can be merged
 If the branch’s destruction request has been selected, it will be destroyed
170
GITLAB / Merge Request
Name of
the repo
Branch’s source
Destination’s branch
Select this button to compare
the two branches
171
GITLAB / Merge Request
One or more reviewer
Just a comment on
what i am merging
Name of the
merge (feature’s
name, what is
fixed, …)
172
GITLAB / Merge Request
Delete the (feature/bugfix/hotfix/…) branch after the merge request
Proceed to the MR
 Each reviewer will receive an email that will notify them about the MR
Commit(s) impact with this merge request
173
GITLAB / Merge Request
Checkout, edit
the branch from
gitlab
Number of
merge
request
associated
to me
We can valid the MR or not
We can add a comment for
the develop that describe
why we cannot valid the MR
If we are okay with the
MR we can launch the
Merge
174
 Create new feature branch (from develop)
using the gitflow (idJIRA=TTSP-1235 /
Description=« Mys first feature »)
 Add new test.c + test.h (fake) file to the repo.
 Add+commit them to the branch
 Push to your branch
 (GITLAB) Make a MR from the feature’s branch
to the develop’s branch
 Add comment to your MR
 Accept and merge your MR
 Watch the result on gitlab
 All branches’s name must be in lowercase
 just replace USERNAME by your nn6 one !
GITLAB / SETTINGS
 CI - Continuous Integration : this is useful for …
 Launching linters (coding style checkerker : cppchecker, pylint, … )
 Building the service/component
 Launching unit tests (with address sanatizer in c++)
 Generating automatic documentation (eg: doxygen)
 Creating docker, deb/rpm/… packages, tarballs, ...
 Building a buildroot firmware
 Creating a VM using Hashicorp packer
175
GITLAB / CI/CD
 CD – Continuous Delivery : this is useful for …
 Adding tag to a docker
 Pushing a docker to a docker’s registry according to the branch (one
registry per branch : develop, integration, main)
 Pushing a rpm/deb/tarball to the package’s registry
 Pushing helm charts to a kubernetes (k8s)
 Deploying images created with packer using Hashicorp Terraform
176
GITLAB / CI/CD
177
GITLAB / CI/CD
Gitlab bring a lot of templates
… / …
 The goal of those template will be to add
a ..gitlab-ci.yml adapt to a language
178
179
GITLAB / CI/CD
# This file is a template, and might need editing before it works on your project.
# You can copy and paste this template into a new `.gitlab-ci.yml` file.
# You should not add this template to an existing `.gitlab-ci.yml` file by using the `include:` keyword.
#
# To contribute improvements to CI/CD templates, please follow the Development guide at:
# https://docs.gitlab.com/ee/development/cicd/templates.html
# This specific template is located at:
# https://gitlab.com/gitlab-org/gitlab/-/blob/master/lib/gitlab/ci/templates/C++.gitlab-ci.yml
# use the official gcc image, based on debian
# can use versions as well, like gcc:5.2
# see https://hub.docker.com/_/gcc/
image: gcc
build:
stage: build
# instead of calling g++ directly you can also use some build toolkit like make
# install the necessary build tools when needed
# before_script:
# - apt update && apt -y install make autoconf
script:
- g++ helloworld.cpp -o mybinary
Docker image that include gcc
 Because the image is a docker file, we can use our image or customize the origginal’s one !
180
artifacts:
paths:
- mybinary
# depending on your build setup it's most likely a good idea to cache
outputs to reduce the build time
# cache:
# paths:
# - "*.o"
# run tests using the binary built before
test:
stage: test
script:
- ./runmytests.sh
deploy:
stage: deploy
script: echo "Define your deployment script!"
environment: production
GITLAB / CI/CD
181
GITLAB / CI/CD
Email received from
gitlab that inform us
that the pipeline has
failled !
 Anothe usefull pipeline :
image: gitlab.enensys.com:4567/tm-testtree/monitor/streamprobe/streamprobe/codequality:latest
stages:
- cppcheck
- sonar
quality:cppcheck:
stage: cppcheck
script:
- ./ci/analysis-cppcheck.sh
artifacts:
name: pages
when: always
paths:
- cppcheck/
- sonar-project.properties
- streamprobe-cppcheck.xml
182
quality:sonar:
stage: sonar
dependencies:
- quality:cppcheck
artifacts:
name: sonar
expire_in: 1 day
paths:
- sonar.log
script:
- sonar-scanner -X > sonar.log
GITLAB / CI/CD
 Sometime pipeline can ask some secret at the CI and/or CD stage :
183
GITLAB / CI/CD
Secrets
 No secrets must
be as is int CI/CD
scripts !
 Settings / CI/CD / Variables
Usefull to rename a project or to move it from one namespace to
another one :
184
GITLAB / CI/CD
 Adding a new secret :
185
GITLAB / CI/CD
It can be a variable or a file
186
GITLAB / CI/CD
History of previous launch
187
GITLAB / CI/CD
Two step/stages wit our pipeline
 Example of pipeline (ci) will do what you want it to do :
188
LINTERS :
cppcheck,
pylint,
dockerlint,
…
BUILD UNITTEST
API
DOCUMENTATION
(doxygen)
 If one step is wrong, the pipeline will stop and send one email.
GITLAB / CI/CD
Create docker
image
…
 The earlier a test is carried out, the faster the problems are handled because it tells the developer that
something is not compliant and thus avoids waiting for functional integration tests
 Example of pipeline (cd) will do what you want it to do :
189
Tag a docker
image
Login to the
registry
Push a docker
image to t he
registry
Launch automatic
tests
 If one step is wrong, the pipeline will stop and send one email.
 For security purpose, all push in production (main branch) MUST be manual !
GITLAB / CI/CD
…
190
Running (now or
previously) can be
viewed here
We can see the exécution’s trace of the pipeline
(see on, next slide)
GITLAB / CI/CD
191
 If one pipeline failled, the
traces are very usefull to know
the origin of the problem.
192
GITLAB / CI/CD
 This is possible to launch CI pipeline every nigtht, in order to have a sanity check on one repo, on a specific branch, …
 We can work (update) the dockers launch for the pipelines :
$ docker login gitlab.enensys.com:4567
Username: gayett
Password:
WARNING! Your password will be stored unencrypted in
/home/ubuntu/.docker/config.json.
Configure a credential helper to remove this warning. See
https://docs.docker.com/engine/reference/commandline/login/#credentials-store
Login Succeeded
 Now we can pull / update and push our docker image that host binaries useful for our
unit test, linters and co ….
193
GITLAB / CI/CD
194
GITLAB / Packages and registries
 Gitlab can manage :
 Container registry :
o Docker images
 Package registry :
o debian (deb)
o redhat packages (RPM)
o tarballs (ZIP, tar.gz, ….)
 Infractructure registry :
o final images or firwmwares (to deploy)
 and more …
195
GITLAB / Wiki
 Each git repo has his own (separated) wiki !
 At any time this is possible to modify the settings of a specify repo
 For security purpose, only maintainers or owners can modify it.
196
GITLAB / Settings
197
GITLAB / Settings
 Settings / General / Advanced / Change path
Usefull to rename a project or to move it from one namespace to
another one :
198
 Settings / Integration
Gitlab can be linked with external tools :
199
GITLAB / Settings
 Settings / Repository
Define main branch at the clone time :
200
GITLAB / Settings
 Settings / Repository / branch default
Specify a pattern as a regexp for branch’s name
201
GITLAB / Settings
 Settings / Repository / protected branches
Avoid any direct push to
main/integration/develop (must use MR)
202
GITLAB / Settings
 Integration with JIRA in order to push SHA1 commit to User Story :
 https://about.gitlab.com/blog/2021/04/12/gitlab-jira-integration-
selfmanaged/
203
GITLAB / Settings
204
 Create a .gitlabci.yaml file from scrach or
using a template)
 Make it work and run it
 If you have time, customize a docker image,
add tools and push it back to the gitlab
docker’s registry.
 All branches’s name must be in lowercase
 just replace USERNAME by your nn6 one !
GITLAB / SETTINGS
GIT ADVANCED
205
Stash
 Because it is not possible to switch to another branch until the
current branch has committed everything, git proposes the use of an
area called stash which allows to save modifications which can be re-
imported by the following :
$ git stash  We backup our current work (on branch XXX)
$ git checkout main
(do something here)
$ git add files …
$ git commit –m “urgent modification”
$ git push origin main
$ git checkout XXX
$ git stash list
$ git stash pop  here we can continue on our previous work
GIT / STASH
207
GIT / STASH
208
Now with
vscode
209
 Add several files (as you want)
 Try to swicth to another branch 
(You should have a problem here)
 Now, stash your current work
 Switch to a branch
(Here we can make something urgent)
 Got back to you previous branch
 List the stash wor
 Pop your last work
(Now we can continue to work)
 All branches’s name must be in lowercase
 just replace USERNAME by your nn6 one !
GITLAB / STASH
LFS aka Large File System
 In order to avoid overloading a git repo with large files which would
ultimately take a long time to clone, git lfs is very useful because it
allows large files to be separated into a separate channel from the
usual clone.
 For that purpose, you must have the git-lfs client installed on your
system.
 https://docs.gitlab.com/ee/topics/git/lfs/
 https://docs.gitlab.com/ee/user/project/settings/index.html#configur
e-project-visibility-features-and-permissions
GIT / LFS
211
GITLAB (GIT)
LFS
 Your gitlab projet must be enabled for that feature :
212
GIT / LFS
 Add filter to git repo for some extension to be managed by git lfs :
 Download and install the Git command line extension.
 Once downloaded and installed, set up Git LFS for your user account by running:
$ git lfs install
 You only need to run this once per user git user account.
In each Git repository where you want to use Git LFS, select the file types you'd like Git
LFS to manage (or directly edit your .gitattributes).
 You can configure additional file extensions at anytime.
$ git lfs track "*.psd"
 Now make sure .gitattributes is tracked:
$ git add .gitattributes
$ git commit –m “add lfs filtering for psd files”
$ git push origin main
213
GIT / LFS
 Note that defining the file types Git LFS should track will not, by itself,
convert any pre-existing files to Git LFS, such as files on other branches
or in your prior commit history. To do that, use the git lfs migrate
command, which has a range of options designed to suit various
potential use cases.
 As a test, just commit and push to gitlab as you normally would ; for
instance, if your current branch is named main:
$ git add file.psd
$ git commit -m "Add photoshop design file"
$ git push origin main
A “git lfs status” command will show you all files managed by git and that
will be pushed to gitlab by this way.
214
GIT / LFS
 For existing git repo, this is possible to cleanup using bfg :
 First clone a fresh copy of your repo, using the --mirror flag :
$ git clone --mirror git@gitlab.enensys.com:training/git/some-big-repo.git
 This is a bare repo, which means your normal files won't be visible, but it is a full copy of the Git database
of your repository, and at this point you should make a backup of it to ensure you don't lose anything.
 Now you can run the BFG to clean your repository up:
$ wget https://repo1.maven.org/maven2/com/madgag/bfg/1.14.0/bfg-1.14.0.jar
$ java -jar ./bfg-1.14.0.jar --strip-blobs-bigger-than 100M some-big-repo.git
 The BFG will update your commits and all branches and tags so they are clean, but it doesn't physically
delete the unwanted stuff. Examine the repo to make sure your history has been updated, and then use the
standard git gc command to strip out the unwanted dirty data, which Git will now recognise as surplus to
requirements:
$ cd some-big-repo.git && git reflog expire --expire=now --all && git gc --prune=now --aggressive
 Finally, once you're happy with the updated state of your repo, push it back up (note that because your
clone command used the --mirror flag, this push will update all refs on your remote server) :
$ git push
 Official repo : https://rtyley.github.io/bfg-repo-cleaner/
215
GIT / LFS
216
GIT / LFS
Now with
vscode
https://github.com/microsoft/vscode-dev-containers/blob/main/script-
library/docs/git-lfs.md
217
 Enable LFS setting on your git repo (GITLAB)
 Check you have git lfs install on your system
 Add GIT lfs support to your repo
 Check the .gitattributes file and add/commit it
 Add a filter with *.mp4 and *.ts files
 Add a ts file and check the file is well tracked
using git-lfs status
 Push all to gitlab and check what is managed
over LFS
 Try to clone you repo in a /tmp directory, just
to check everything.
 All branches’s name must be in lowercase
 just replace USERNAME by your nn6 one !
GITLAB / LFS
Submodules
 Imagine a part of git repo that could be factored between several other
repos such as a submodule that would be attached.
 To do this, git sub-modules were invented to allow you to link a repo
 Create a git repo that will be linked
 Add the repo to each repo that will need to be linked
 Commit and push the .gitmodules file and the folder of the submodule itself
GIT / SUBMODULE
219
GIT REPO
FACTORIZED
GIT
REPO A
GIT
REPO B
 Immagine you are inside a repo git already cloned. You can add the fatorized repo
like this :
~/Workspaces/first-project (develop)$ git submodule add
git@gitlab.enensys.com:training/git/DbConnector
Cloning into 'DbConnector'...
remote: Counting objects: 11, done.
remote: Compressing objects: 100% (10/10), done.
remote: Total 11 (delta 0), reused 11 (delta 0)
Unpacking objects: 100% (11/11), done.
Checking connectivity... done.
By default, submodules will add the subproject into a directory named the same as the
repository, in this case “DbConnector”.
GIT / SUBMODULE
220
 If you run git status at this point, you’ll notice a few things.
~/Workspaces/first-project (develop)$ git status
On branch master
Your branch is up-to-date with 'origin/master'.
Changes to be committed:
(use "git reset HEAD <file>..." to unstage)
new file: .gitmodules
new file: DbConnector
 First you should notice the new .gitmodules file. This is a configuration file that stores the mapping between the project’s
URL and the local subdirectory you’ve pulled it into:
[submodule "DbConnector"]
path = DbConnector
url = git@gitlab.enensys.com:training/git/DbConnector
 If you have multiple submodules, you’ll have multiple entries in this file. It’s important to note that this file is version-
controlled with your other files, like your .gitignore file.
 It’s pushed and pulled with the rest of your project. This is how other people who clone this project know where to get the
submodule projects from.
221
GIT / SUBMODULE
 Don’t forget to commit and push the .gitmodules file and the repo that host the factorized git repo :
~/Workspaces/first-project (develop)$ git commit -am 'Add DbConnector module'
[master fb9093c] Add DbConnector module
2 files changed, 4 insertions(+)
create mode 100644 .gitmodules
create mode 160000 DbConnector
Notice the 160000 mode for the DbConnector entry. That is a special mode in Git that basically means you’re
recording a commit as a directory entry rather than a subdirectory or a file.
 To update the revision of a submodule within a git repo, you can just enter into the submodule folder, then
switch to a new sha1, tag or branch of the submodule. Then got back at the root path of the repo that host
the git submodule and just commit the folder.
 Lastly, push these changes:
~/Workspaces/first-project (develop)$ git push origin master
222
GIT / SUBMODULE
 When cloning a repo, the .gitmodules is pull with the other files but the
folder of each submodule are empty.
 To initialise the folder we can use the following commands :
 ~/Workspaces/first-project (develop)$ git submodule init
 ~/Workspaces/first-project (develop)$ git submodule update
 To clone and initialize each submodule, you can do it that way :
 ~/Workspaces/first-project (develop)$ git clone --recurse-submodules
git@gitlab.enensys.com:training/git/first-project.git
223
GIT / SUBMODULE
GIT / SUBMODULE
224
Now with
vscode
https://marketplace.visualstudio.com/items?itemName=ivanhofer.git-
assistant#:~:text='Git%20(Submodule)%20Assistant',and%20assists%20yo
u%20with%20fixes.
225
 Clone the repo « my-first-project » from the
HEAD as a submodule
https://gitlab.enensys.com/training/git/first-
project
 Watch the .gitmodules file
 Add the .gitmodules file and the folder of the
repo cloned
 Commit and push all to gitlab
 All branches’s name must be in lowercase
 just replace USERNAME by your nn6 one !
GITLAB / SUBMODULES
MORE HELP ABOUT GIT
226
 LINKS :
o https://git-scm.com/doc
o https://git-scm.com/docs
o https://git-scm.com/book/en/v2
o https://git-scm.com/doc/ext
o https://git-scm.com/docs/gittutorial
o https://gitimmersion.com/
o https://github.com/sensorflo/git-draw/wiki
o http://www-cs-students.stanford.edu/~blynn/gitmagic/
o https://git-scm.com/docs/giteveryday
o https://nulab.com/learn/software-development/git-tutorial/git-basics/
o https://github.com/progit/progit2-fr/releases/download/2.1.70/progit.pdf
o https://github.com/progit/progit2/releases/download/2.1.360/progit.pdf
https://www.amazon.fr/s?k=git&i=stripbooks&__mk_fr_FR=%C3%85M%C3%85%C5%BD%C3%95%C3%91&crid=424VPI44G9P
5&sprefix=git%2Cstripbooks%2C105&ref=nb_sb_noss_1
GIT / HELP
227
(Official printed documentation)
228
 If you want to go more in detail about dev(sec)ops automations, I can
do a third training specific to CI/CI chain-oriented CI, to build a docker
image, push a helm chart into a kubernetes, build a buildroot image /
yocto, ...... gitlab can do everything :-)!
MORE
229
Next part, the NN6 official :
gitflow, versionning and svn
migration.
230
ENENSYS
4A rue des Buttes
CS 37734
35 577 Cesson-Sévigné – France
Phone (+33) 1 70 72 51 70
Email contact@test-tree.com
www.enensys.com
231

Contenu connexe

Similaire à GIT training - advanced for software projects

Github - Git Training Slides: Foundations
Github - Git Training Slides: FoundationsGithub - Git Training Slides: Foundations
Github - Git Training Slides: FoundationsLee Hanxue
 
Understanding Pseudo-Versions Moving to Go 1.13 What is in Go 1.14+ for Modules
Understanding Pseudo-Versions Moving to Go 1.13 What is in Go 1.14+ for ModulesUnderstanding Pseudo-Versions Moving to Go 1.13 What is in Go 1.14+ for Modules
Understanding Pseudo-Versions Moving to Go 1.13 What is in Go 1.14+ for ModulesMitali Bisht
 
Git as version control for Analytics project
Git as version control for Analytics projectGit as version control for Analytics project
Git as version control for Analytics projectNag Arvind Gudiseva
 
Git - Intro to the Basics of DVCS
Git - Intro to the Basics of DVCSGit - Intro to the Basics of DVCS
Git - Intro to the Basics of DVCSMatthew McCullough
 
Git - Intro to the Basics of DVCS
Git - Intro to the Basics of DVCSGit - Intro to the Basics of DVCS
Git - Intro to the Basics of DVCSMatthew McCullough
 
Bedjango talk about Git & GitHub
Bedjango talk about Git & GitHubBedjango talk about Git & GitHub
Bedjango talk about Git & GitHubBeDjango
 
Scaling Development Environments with Docker
Scaling Development Environments with DockerScaling Development Environments with Docker
Scaling Development Environments with DockerDocker, Inc.
 
Git intro hands on windows with msysgit
Git intro hands on windows with msysgitGit intro hands on windows with msysgit
Git intro hands on windows with msysgitGeshan Manandhar
 
Git dvcs and Information Security Review
Git dvcs and Information Security ReviewGit dvcs and Information Security Review
Git dvcs and Information Security Reviewdchaffiol
 
Coscup x ruby conf tw 2021 google cloud buildpacks 剖析與實踐
Coscup x ruby conf tw 2021  google cloud buildpacks 剖析與實踐Coscup x ruby conf tw 2021  google cloud buildpacks 剖析與實踐
Coscup x ruby conf tw 2021 google cloud buildpacks 剖析與實踐KAI CHU CHUNG
 
Security of Go Modules - SF Meetup
Security of Go Modules - SF MeetupSecurity of Go Modules - SF Meetup
Security of Go Modules - SF MeetupDeep Datta
 
Git & version control crash course
Git & version control crash course Git & version control crash course
Git & version control crash course Eslam Saeed
 
Introduction to GitHub, Open Source and Tech Article
Introduction to GitHub, Open Source and Tech ArticleIntroduction to GitHub, Open Source and Tech Article
Introduction to GitHub, Open Source and Tech ArticlePRIYATHAMDARISI
 
My Notes from https://www.codeschool.com/courses/git-real
My Notes from  https://www.codeschool.com/courses/git-realMy Notes from  https://www.codeschool.com/courses/git-real
My Notes from https://www.codeschool.com/courses/git-realEneldo Serrata
 

Similaire à GIT training - advanced for software projects (20)

Introduction to Git and Github
Introduction to Git and GithubIntroduction to Git and Github
Introduction to Git and Github
 
git-docker.pdf
git-docker.pdfgit-docker.pdf
git-docker.pdf
 
Gitops Hands On
Gitops Hands OnGitops Hands On
Gitops Hands On
 
Github - Git Training Slides: Foundations
Github - Git Training Slides: FoundationsGithub - Git Training Slides: Foundations
Github - Git Training Slides: Foundations
 
Understanding Pseudo-Versions Moving to Go 1.13 What is in Go 1.14+ for Modules
Understanding Pseudo-Versions Moving to Go 1.13 What is in Go 1.14+ for ModulesUnderstanding Pseudo-Versions Moving to Go 1.13 What is in Go 1.14+ for Modules
Understanding Pseudo-Versions Moving to Go 1.13 What is in Go 1.14+ for Modules
 
Git as version control for Analytics project
Git as version control for Analytics projectGit as version control for Analytics project
Git as version control for Analytics project
 
Git - Intro to the Basics of DVCS
Git - Intro to the Basics of DVCSGit - Intro to the Basics of DVCS
Git - Intro to the Basics of DVCS
 
Git and git hub basics
Git and git hub basicsGit and git hub basics
Git and git hub basics
 
Composer and Git in Magento
Composer and Git in MagentoComposer and Git in Magento
Composer and Git in Magento
 
Git - Intro to the Basics of DVCS
Git - Intro to the Basics of DVCSGit - Intro to the Basics of DVCS
Git - Intro to the Basics of DVCS
 
Bedjango talk about Git & GitHub
Bedjango talk about Git & GitHubBedjango talk about Git & GitHub
Bedjango talk about Git & GitHub
 
Scaling Development Environments with Docker
Scaling Development Environments with DockerScaling Development Environments with Docker
Scaling Development Environments with Docker
 
Github By Nyros Developer
Github By Nyros DeveloperGithub By Nyros Developer
Github By Nyros Developer
 
Git intro hands on windows with msysgit
Git intro hands on windows with msysgitGit intro hands on windows with msysgit
Git intro hands on windows with msysgit
 
Git dvcs and Information Security Review
Git dvcs and Information Security ReviewGit dvcs and Information Security Review
Git dvcs and Information Security Review
 
Coscup x ruby conf tw 2021 google cloud buildpacks 剖析與實踐
Coscup x ruby conf tw 2021  google cloud buildpacks 剖析與實踐Coscup x ruby conf tw 2021  google cloud buildpacks 剖析與實踐
Coscup x ruby conf tw 2021 google cloud buildpacks 剖析與實踐
 
Security of Go Modules - SF Meetup
Security of Go Modules - SF MeetupSecurity of Go Modules - SF Meetup
Security of Go Modules - SF Meetup
 
Git & version control crash course
Git & version control crash course Git & version control crash course
Git & version control crash course
 
Introduction to GitHub, Open Source and Tech Article
Introduction to GitHub, Open Source and Tech ArticleIntroduction to GitHub, Open Source and Tech Article
Introduction to GitHub, Open Source and Tech Article
 
My Notes from https://www.codeschool.com/courses/git-real
My Notes from  https://www.codeschool.com/courses/git-realMy Notes from  https://www.codeschool.com/courses/git-real
My Notes from https://www.codeschool.com/courses/git-real
 

Dernier

Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...stazi3110
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...MyIntelliSource, Inc.
 
Folding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesFolding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesPhilip Schwarz
 
Asset Management Software - Infographic
Asset Management Software - InfographicAsset Management Software - Infographic
Asset Management Software - InfographicHr365.us smith
 
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio, Inc.
 
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...gurkirankumar98700
 
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfGOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfAlina Yurenko
 
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataAdobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataBradBedford3
 
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideBuilding Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideChristina Lin
 
Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Andreas Granig
 
Intelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmIntelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmSujith Sukumaran
 
Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...OnePlan Solutions
 
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...soniya singh
 
Cloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEECloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEEVICTOR MAESTRE RAMIREZ
 
Implementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureImplementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureDinusha Kumarasiri
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...MyIntelliSource, Inc.
 
The Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdfThe Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdfPower Karaoke
 
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxKnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxTier1 app
 
software engineering Chapter 5 System modeling.pptx
software engineering Chapter 5 System modeling.pptxsoftware engineering Chapter 5 System modeling.pptx
software engineering Chapter 5 System modeling.pptxnada99848
 

Dernier (20)

Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
 
Folding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesFolding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a series
 
Asset Management Software - Infographic
Asset Management Software - InfographicAsset Management Software - Infographic
Asset Management Software - Infographic
 
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
 
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
 
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfGOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
 
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort ServiceHot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
 
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataAdobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
 
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideBuilding Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
 
Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024
 
Intelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmIntelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalm
 
Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...
 
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
 
Cloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEECloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEE
 
Implementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureImplementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with Azure
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
 
The Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdfThe Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdf
 
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxKnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
 
software engineering Chapter 5 System modeling.pptx
software engineering Chapter 5 System modeling.pptxsoftware engineering Chapter 5 System modeling.pptx
software engineering Chapter 5 System modeling.pptx
 

GIT training - advanced for software projects

  • 1. lundi 13 mars 2023 GIT TRAINING - Advanced Thierry GAYET
  • 2.  The purpose of this training will be to:  Reminder on git commands  Devops / devsecops  Gitlab  Advanced usage of GIT  CI and CD Have a good training  GOAL 2 scan me
  • 4.  After the two first modules of the git training, we will continue step by step in command line for the nerds/geeks or using a graphical tool such as Visual code studio from Microsoft that can be run on gnu/linux, Ms Windows or Mac OS X.  We will use this gitlab project : https://gitlab.enensys.com/training/git/first-project  You must have an access to gitlab (and your public ssh (rsa) key declared : ~/.ssh/id_rsa.pub) GIT / PURPOSE 4
  • 5. ❑ WINDOWS : ❑ https://gitforwindows.org/ ❑ WSL / Ubuntu 22.04 LTS (then see above GNU/Linux) https://linuxconfig.org/ubuntu-22-04-on-wsl-windows-subsystem-for-linux ❑ MAC OS X : ❑ https://sourceforge.net/projects/git-osx-installer/files/git-2.23.0-intel- universal-mavericks.dmg/download?use_mirror=autoselect ❑ (homebrew) brew install git + brew install git-gui ❑ (MacPort) sudo port install git ❑ Dmg : https://sourceforge.net/projects/git-osx-installer/ ❑ GNU/LINUX : ❑ sudo apt-get install git-all gitg gitk git-man git-doc git-gui git-flow git-svn ❑ dnf install git-all GIT / INSTALL 5
  • 6. GIT / INSTALL (LFS) 6 ❑ WINDOWS : ❑ GIT-LFS : https://git-lfs.com/ https://linuxconfig.org/ubuntu-22-04-on-wsl-windows-subsystem-for-linux ❑ MAC OS X : ❑ (homebrew) brew install git-lfs ❑ (MacPort) sudo port install git-lfs ❑ GNU/LINUX : ❑ sudo apt-get git-lfs ❑ dnf install git-lfs
  • 7. GIT / INSTALL (VSCODE) 7 • https://code.visualstudio.com/ • https://vscodium.com/  Visual Studio Code (aka VSCODE) :
  • 8.  Recommended Visual studio code extension:  Git graph  Git Blame  Git (Submodule) Assistant  Git LFS File Locking UI  gitlab-ci-validator  … 8 GIT / CONFIG
  • 17. 17 GIT / CONFIG dev(sec)ops / K8s charts helm
  • 28. GIT / PURPOSE (VSCODE) 28  1. The menu bar  2. VSCode Sidebar  3. VSCode Explorer  4. Debug Console/Terminal  5. Document Display/Editor
  • 29. GIT / PURPOSE (VSCODE) 29
  • 30. 30 GIT / PURPOSE (VSCODE)
  • 31.  VSCODE general usage :  https://code.visualstudio.com/docs  https://code.visualstudio.com/docs/terminal/basics  https://code.visualstudio.com/docs/editor/debugging  https://code.visualstudio.com/docs/languages/cpp  https://code.visualstudio.com/docs/languages/python  https://code.visualstudio.com/docs/languages/javascript  https://code.visualstudio.com/docs/languages/typescript  https://code.visualstudio.com/docs/languages/php  https://code.visualstudio.com/docs/languages/json  https://code.visualstudio.com/docs/sourcecontrol/overview  https://code.visualstudio.com/docs/cpp/introvideos-cpp  https://code.visualstudio.com/docs/containers/overview  https://code.visualstudio.com/docs/devcontainers/containers  https://www.youtube.com/watch?v=CZzQn2X8Ja8 GIT / PURPOSE (VSCODE) 31
  • 32. Reminder on git commands Command line & Visual Studio Code (Vscode) 32
  • 35.  Customize your git settings : $ git config --global user.name "John Doe" $ git config --global user.email john.doe@enensys.com $ git config --global color.ui auto $ git config --global core.editor "nano"  Update your ~/.gitconfig file : [diff] tool = default-difftool [difftool "default-difftool"] cmd = code --wait --diff $LOCAL $REMOTE [merge] tool = code [mergetool "code"] cmd = code --wait --merge $REMOTE $LOCAL $BASE $MERGED GIT / CONFIG 35
  • 36.  Check your local git setting : ~/Workspaces/training/fpga (main)$ git config --list --show-origin file:/etc/gitconfig filter.lfs.clean=git-lfs clean -- %f file:/etc/gitconfig filter.lfs.smudge=git-lfs smudge -- %f file:/etc/gitconfig filter.lfs.process=git-lfs filter-process file:/etc/gitconfig filter.lfs.required=true file:/home/linux/.gitconfig user.name=Thierry GAYET file:/home/linux/.gitconfig user.email=Thierry.Gayet@enensys.com file:/home/linux/.gitconfig core.editor=nano file:/home/linux/.gitconfig color.branch=auto file:/home/linux/.gitconfig color.status=auto file:/home/linux/.gitconfig color.diff=auto file:/home/linux/.gitconfig color.interactive=auto file:/home/linux/.gitconfig alias.co=checkout file:/home/linux/.gitconfig alias.ci=commit file:/home/linux/.gitconfig alias.br=branch file:/home/linux/.gitconfig alias.st=status file:/home/linux/.gitconfig alias.ls=log --oneline --decorate file:/home/linux/.gitconfig alias.lsa=log --oneline --decorate --all (…) 36 GIT / CONFIG You can update / customie your git config
  • 37.  Upgrade your ~/.bashrc usefull for all commands : (...) parse_git_branch() { git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* (.*)/(1)/’ } export PS1="u@h [e[32m]w [e[91m]$(parse_git_branch)[e[00m]$ " (...)  It will colorize the prompt command line and display the name of the git repo and the branch’s name : linux@des126 ~/Workspaces/training/first-project (feature/ttsp-1234/my-first- files)$ GIT / CONFIG 37
  • 38.  You can add/change the git user in the Extension Git Graph easily.  Go to the Extensions tab and install Git Graph.  Go to the Source Control tab  Click on the View Git Graph  Click on the Repository Settings  In the User Details section, click Edit and change the Git Username and Email. 38 GIT / CONFIG
  • 39.  Several videos on VS CODE and GIT :  https://code.visualstudio.com/docs/sourcecontrol/overview  https://www.youtube.com/watch?v=i_23KUAEtUM&embeds_euri=https%3A %2F%2Fcode.visualstudio.com%2F&feature=emb_imp_woyt  https://www.youtube.com/watch?v=E6ADS2k8oNQ&embeds_euri=https%3A %2F%2Fcode.visualstudio.com%2F&feature=emb_imp_woyt  https://www.youtube.com/watch?v=b9LTz6joMf8&embeds_euri=https%3A% 2F%2Fcode.visualstudio.com%2F&feature=emb_imp_woyt  https://www.youtube.com/watch?v=HosPml1qkrg&embeds_euri=https%3A %2F%2Fcode.visualstudio.com%2F&feature=emb_imp_woyt 39 GIT / CONFIG
  • 48. Clone
  • 49. GIT / CLONE 49  Clone your GIT repo : $ mkdir –p ~/Workspace && cd ~/Workspace $ git clone git@gitlab.enensys.com:training/git/first-project.git (Needs to have uploaded his ssh key (~/.ssh/id_rsa.pub) in his gitlab profile) Cloning into 'test’... remote: Enumerating objects: 3, done. remote: Counting objects: 100% (3/3), done. remote: Compressing objects: 100% (2/2), done. remote: Total 3 (delta 0), reused 0 (delta 0), pack-reused 0 Receiving objects: 100% (3/3), done. OR $ git clone https://gitlab.enensys.com/training/git/first-project.git Cloning into 'first-project’... Username for 'https://gitlab.enensys.com': gayett Password for 'https://gayett@gitlab.enensys.com’: remote: Enumerating objects: 3, done. remote: Counting objects: 100% (3/3), done. remote: Compressing objects: 100% (2/2), done. remote: Total 3 (delta 0), reused 0 (delta 0), pack-reused 0 Receiving objects: 100% (3/3), done.
  • 50.  By default a git repo take the repo from the server but can be change if we provide a name at the clone time : $ git clone git@gitlab.enensys.com:training/git/first-project.git first-projet-2 Cloning into ‘first-project-2’... remote: Enumerating objects: 3, done. remote: Counting objects: 100% (3/3), done. remote: Compressing objects: 100% (2/2), done. remote: Total 3 (delta 0), reused 0 (delta 0), pack-reused 0 Receiving objects: 100% (3/3), done. 50 GIT / CLONE
  • 51.  We can now check branches : $ cd first-project/ ~/Workspaces/first-project (main)$ ~/Workspaces/first-project (main)$ git branch * main ~/Workspaces/first-project (main)$ git branch –a * main remotes/origin/HEAD -> origin/main remotes/origin/main GIT / CLONE 51 Local branch(es) Local and remotes branches Name of the current branch : main Name of the git repo just cloned
  • 52.  Now, using visual code : GIT / CLONE 52 Select that we want to clone a git repo.
  • 53. 53 GIT / CLONE Just copy/paste the url of the git repo to clone Valid by clicking on the « Clone from url »
  • 54. 54 GIT / CLONE VS code will ask you to choose a folder where you want to clone your git repo : Confirm by clicking on that button
  • 55.  Finally, we can open the repo just cloned :  We can also confirm that we trust the git repo : 55 GIT / CLONE Say that we want to open the source of the git repo just cloned Check that this repo is trusted And validate by clicking on the button "Yes, i trust the authors ...."
  • 56. 56 GIT / CLONE The project is now available using visual code. This is an empty repo so this is normal if there is nothing inside ! Default’s branch (main)
  • 57. 57 GIT / CLONE Local branch Remote branch (on the gitlab server)
  • 59.  We can dump the repo’s config : ~/Workspaces/fpga (main)$ cat .git/config [core] repositoryformatversion = 0 filemode = true bare = false logallrefupdates = true [remote "origin"] url = git@gitlab.enensys.com:tm-terrestrial/satcaster2/fpga.git fetch = +refs/heads/*:refs/remotes/origin/* [branch "main"] remote = origin merge = refs/heads/main [gitg] mainline = "" 59 GIT / INSPECT
  • 60.  Check the remotes : ~/Workspaces/fpga (main)$ git remote –v origin git@gitlab.enensys.com:tm-terrestrial/satcaster2/fpga.git (fetch) origin git@gitlab.enensys.com:tm-terrestrial/satcaster2/fpga.git (push) 60 GIT / INSPECT
  • 61.  Check the local and remote branches : ~/Workspaces/fpga (main)$ git branch –a * main remotes/origin/HEAD -> origin/main remotes/origin/main ~/Workspaces/fpga (main)$ git log commit 4f9d0d3a053cc81cd74980276cccb6b045cf5529 (HEAD -> main, origin/main, origin/HEAD) Author: Olivier PIEDCOQ olivier.piedcoq@enensys.com Date: Wed Mar 8 16:17:08 2023 +0100 remove satcasterII.rbf ; only satcasterII.rbf.gz in git commit 9e172333d2d25873fa4b787e58db8394c1f7db2d Author: Olivier PIEDCOQ <olivier.piedcoq@enensys.com>Date: Tue Jan 31 09:32:17 2023 +0000 use last revision of common_regs & giga_ctrl commit 0a78c28487f4e7ad0f80d105f96676bae2e57b0a Author: Olivier PIEDCOQ olivier.piedcoq@enensys.com (…) 61 GIT / INSPECT
  • 62. 62 GIT / INSPECT  Inspect the previous commits : ~/Workspaces/fpga (main)$ git log commit 4f9d0d3a053cc81cd74980276cccb6b045cf5529 (HEAD -> main, origin/main, origin/HEAD) Author: Olivier PIEDCOQ olivier.piedcoq@enensys.com Date: Wed Mar 8 16:17:08 2023 +0100 remove satcasterII.rbf ; only satcasterII.rbf.gz in git commit 9e172333d2d25873fa4b787e58db8394c1f7db2d Author: Olivier PIEDCOQ <olivier.piedcoq@enensys.com>Date: Tue Jan 31 09:32:17 2023 +0000 use last revision of common_regs & giga_ctrl commit 0a78c28487f4e7ad0f80d105f96676bae2e57b0a Author: Olivier PIEDCOQ olivier.piedcoq@enensys.com (…)
  • 63. ~/Workspaces/training/fpga (main)$ git log --oneline --all --decorate --graph * 4f9d0d3 (HEAD -> main, origin/main, origin/HEAD) remove satcasterII.rbf ; only satcasterII.rbf.gz in git * 9e17233 use last revision of common_regs & giga_ctrl * 0a78c28 update .gitignore to ignore .log file * 9831cd3 remove unused component definition * abb752f update to quartus 22.2 * b7f7582 update to quartus 22.2 * a081ad3 remove unused dcboard_33_io output (NA in hdm2-sat2 board), remove unused mdio_control(no ip extension card available in hdm2-sat2) * bfb10e5 update git ignore file * b14c890 Merge branch 'main' of gitlab.enensys.com:tm-terrestrial/satcaster2/fpga | | * 41f9eb2 fix firmware name * | d171cda regenerate firmware after git migration |/ * 37d6331 fix migration * 49c2a35 add common modules checkout script; fix directory structure due to git migration; remove inband configuration module * 360634b remove unsued pcie_ts_read_arria_10_pkg package fix rtp_mgnt component instantiation * 786c99e add svn revision & fpga occupation summary (…) 63 GIT / INSPECT
  • 64. 64 $ gitk GIT / INSPECT
  • 65. $ gitg 65 GIT / INSPECT
  • 66. 66 GIT / INSPECT Using the git graph extension, we can view the branch, commits, merges (see on next slide) Now with vscode
  • 67. 67 GIT / INSPECT Using the git graph extension
  • 68. 68 GIT / INSPECT Show Git Output
  • 69.  Clone the « first projet » repo using the git protocol  Inspect it 69 GIT / BRANCHES
  • 70. Create branches for the gitflow
  • 71.  The goal is to apply the NN6 gitflow that must be apply on all git repo :  main : the stable branch similar to the production  integration : the branch used for intermediate integration is the equivalent of a preproduction  development : the unstable branch used to merge the developments to be integrated 71 GIT / BRANCHES
  • 72. GITFLOW 72 ❑ The official GITFLOW to be use is the following one : main/stable/production preprod/integration Development/unstable HOTFIX / ID-JIRA / DESCRIPTION BUGFIX / ID-JIRA / DESCRIPTION FEATURE / ID-JIRA / DESCRIPTION TAG1 TAG2 rebase rebase rebase Merge request Merge request Merge request Merge request MR Merge request Push + merge request Push + merge request Push + merge request
  • 73. 73 GITFLOW Main (stable’s branch) Integration’s branch Develop (unstable’s branch) HOTFIX branch branch branch Push on the bugfix branch BUGFIX FEATURE Rebase branch branch Rebase Push + Merge Request Push + Merge Request All branches merged into this integration branch should reflect what will be described in the final release note. RC 9.1.0 RC 9.1.1 HOTFIX branch Merge Request Merge Request Merge Request Merge Request 9.0.0 9.1.1 Merge Request Push on the bugfix branch Merge Request Merge Request CI : linters (gitlab) Hotfix release Official release Hotfix release If the hotfix is clean! If the hotfix is clean! Jenkins nightly build + sanity tests Jenkins build + focus test on the hotfix Jenkins build + focus test on the hotfix Jenkins build + complete tests Jenkins nightly build + sanity tests
  • 74. 74 GITFLOW main integration develop hotfix bugfix feature Push Merge request Create branch Create branch Create branch Create branch Create branch Rebase Hotfix release Jenkins build + focus test on the hotfix Jenkins nightly build + sanity tests Push Merge request Rebase Jenkins nightly build + sanity tests CI : linters (gitlab) Merge request Merge request Jenkins build + complete tests 9.0.0 9.1.1 Official release Merge request
  • 75. 75  Create branches (in two time) : ~/Workspaces/first-project (main)$ git branch * main ~/Workspaces/first-project (main)$ git branch integration ~/Workspaces/first-project (main)$ git branch integration * main ~/Workspaces/first-project (main)$ git checkout integration Switched to branch 'integration’ ~/Workspaces/first-project (integration)$ git branch * integration main ~/Workspaces/first-project (integration)$ git branch develop ~/Workspaces/first-project (integration)$ git branch develop * integration main ~/Workspaces/first-project (integration)$ git checkout develop Switched to branch ~/Workspaces/first-project (develop)$ git branch * develop integration main  Git branch <branch_name> create a new branch  Git checkout <branch_name> switch to an existing branch GIT / BRANCHES
  • 76.  Create branches and switch (with the same command) : ~/Workspaces/first-project (main)$ git branch * main ~/Workspaces/first-project (main)$ git checkout -b integration Switched to a new branch 'integration’ ~/Workspaces/first-project (integration)$ git branch * integration main ~/Workspaces/first-project (integration)$ git checkout -b develop Switched to a new branch 'develop’ ~/Workspaces/first-project (develop)$ git branch * develop integration main 76 GIT / BRANCHES  Git checkout –b <branch_name> create and switch to the new branch
  • 77.  After the creation all branches are just local and must be pushed to the remote (called origin by default) : ~/Workspaces/first-project (hotfix/ttsp-1245/Fix-database-problem)$ git branch -a develop feature/TTSP-27-37/launch-a-vmaf-analysis * hotfix/ttsp-1245/Fix-database-problem integration main remotes/origin/HEAD -> origin/main remotes/origin/main ~/Workspaces/first-project (hotfix/ttsp-1245/Fix-database-problem)$ git checkout integration Switched to branch 'integration’ ~/Workspaces/first-project (integration)$ git push origin integration Total 0 (delta 0), reused 0 (delta 0), pack-reused 0 remote: remote: To create a merge request for integration, visit: remote: https://gitlab.enensys.com/training/git/first-project/-/merge_requests/new?merge_request%5Bsource_branch%5D=integration remote: To gitlab.enensys.com:training/git/first-project.git * [new branch] integration -> integration 77 GIT / BRANCHES The main’s branch is the default branch juste clone, so we don’t have to create or push it !
  • 78. 78 GIT / BRANCHES ~/Workspaces/first-project (integration)$ git branch -a develop feature/TTSP-27-37/launch-a-vmaf-analysis hotfix/ttsp-1245/Fix-database-problem * integration main remotes/origin/HEAD -> origin/main remotes/origin/integration remotes/origin/main ~/Workspaces/first-project (integration)$ git checkout develop Switched to branch 'develop’ ~/Workspaces/first-project (develop)$ git branch * develop feature/TTSP-27-37/launch-a-vmaf-analysis hotfix/ttsp-1245/Fix-database-problem integration main The integration’s branch is now pushed on the remote origin server !
  • 79. 79 GIT / BRANCHES ~/Workspaces/first-project (develop)$ git push origin develop Total 0 (delta 0), reused 0 (delta 0), pack-reused 0 remote: remote: To create a merge request for develop, visit: remote: https://gitlab.enensys.com/training/git/first-project/-/merge_requests/new?merge_request%5Bsource_branch%5D=develop remote: To gitlab.enensys.com:training/git/first-project.git * [new branch] develop -> develop ~/Workspaces/first-project (develop)$ git branch -a * develop feature/TTSP-27-37/launch-a-vmaf-analysis hotfix/ttsp-1245/Fix-database-problem integration main remotes/origin/HEAD -> origin/main remotes/origin/develop remotes/origin/integration remotes/origin/main The develop’s branch is now pushed on the remote origin server !
  • 80. 80 GIT / BRANCHES All your branches are well done !
  • 81. 81 GIT / BRANCHES We can create the integration’s branch The default’s branch is main Now with vscode
  • 82. 82 GIT / BRANCHES We are now on the integration’s branch
  • 83. 83 GIT / BRANCHES The branch is integration We can create the integration’s branch
  • 84. 84 GIT / BRANCHES We are now on the develop’s branch
  • 85. 85 GIT / BRANCHES By clicking on the branch’s name it will display all one Here is a summary of the branches created localy We will see how to push them to the gitlab server
  • 86. 86 GIT / BRANCHES Right click on the branch’s name
  • 87. 87 GIT / BRANCHES Always avoid push force !
  • 88. 88 GIT / BRANCHES The linux integration is now on the gitlab server (origin)
  • 89. 89 GIT / BRANCHES The Intégration branch is now on Gitlab  We can also push the develop’s branch as well !
  • 90.  Create the following branches (from main) :  main-USERNAME  integration-USERNAME  develop-USERNAME  Push your all your branches to GITLAB (origin) 90 GIT / BRANCHES  All branches’s name must be in lowercase  just replace USERNAME by your nn6 one !
  • 92.  Now that we are on the develop’s branch, we can create feature branch : ~/Workspaces/first-project (develop)$ git branch –a * develop integration main remotes/origin/HEAD -> origin/main remotes/origin/main ~/Workspaces/first-project (develop)$ git checkout -b feature/ttsp-2737/launch-a-vmaf-analysis Switched to a new branch 'feature/ttsp-2737/launch-a-vmaf-analysis’ ~/Workspaces/first-project (feature/ttsp-2737/launch-a-vmaf-analysis)$ git branch develop * feature/TTSP-27-37/launch-a-vmaf-analysis integration main  The workflow is similar with bugfix  eg: bugfix/ttsp-1245/Fix-a-memory-leak 92 GIT / BRANCHES
  • 93.  We can create a hotfix branch from the main’s branch : ~/Workspaces/first-project (feature/TTSP-27-37/launch-a-vmaf-analysis)$ git checkout main Switched to branch 'main' Your branch is up to date with 'origin/main’. ~/Workspaces/first-project (main)$ git checkout -b hotfix/ttsp-1245/Fix-database-problem Switched to a new branch 'hotfix/ttsp-1245/Fix-database-problem' ~/Workspaces/first-project (hotfix/ttsp-1245/Fix-database-problem)$ git branch develop feature/TTSP-27-37/launch-a-vmaf-analysis * hotfix/ttsp-1245/Fix-database-problem integration main 93 GIT / BRANCHES
  • 94. 94 GIT / BRANCHES We are on the develop’s branch Select « Create new branch from » Because we are already on the develop’s branch this is possible to select « create new branch’s name (from the current’s one. We already experiment that way so we will use another one. Now with vscode FEATURE / BUGFIX
  • 95. 95 GIT / BRANCHES Comfirm that we want to start from the develop’s branch
  • 96. 96 GIT / BRANCHES Now we can fill the right branch’s pattern feature/id-jira/description bugfix/id-jira/description and valid with ENTER
  • 97. 97 The feature branch’s name is correct GIT / BRANCHES
  • 98. 98 GIT / BRANCHES Comfirm that we want to start from the main’s branch HOTFIX
  • 99. 99 GIT / BRANCHES Now we can fill the right branch’s pattern hotfix/id-jira/description and valid with ENTER
  • 100. 100 GIT / BRANCHES The hotfix branch’s name is correct  We can also push the feature/bugfix/hotfix branches to gitlab !
  • 101.  Create one branch (from main-USERNAME) :  hotfix/ttsp-1234/USERNAME/memory-leak  Create the two branches (from develop- USERNAME) :  feature/ttsp-4567/USERNAME/vmaf-sampling  bugfix/ttsp-7890/USERNAME/database-issue  Push your all your branches to GITLAB (origin) 101 GIT / BRANCHES  All branches’s name must be in lowercase  just replace USERNAME by your nn6 one !
  • 102. Files
  • 103.  Now we will create two files :  hello.c #include <stdio.h> int main() { printf("Hello, NN6 !"); return 0; } 103 GIT / FILES
  • 104.  And a Makefile : all: gcc –c ./hello.c –o ./hello.o gcc ./hello.o –o ./hello run: ./hello clean: rm –f ./hello.o ./hello 104 GIT / FILES
  • 105.  First of all, create a working branch for your new feature (from develop) : ~/Workspaces/first-project (develop)$ git checkout -b feature/ttsp- 1234/my-first-files Switched to a new branch 'feature/ttsp-1234/my-first-files' 105 GIT / FILES
  • 106.  We can now add the two files : ~/Workspaces/first-project (feature/ttsp-1234/my-first-files)$ git status On branch main Your branch is up to date with 'origin/main'. Untracked files: (use "git add <file>..." to include in what will be committed) Makefile hello.c nothing added to commit but untracked files present (use "git add" to track) ~/Workspaces/first-project (feature/ttsp-1234/my-first-files)$ git add Makefile hello.c ~/Workspaces/first-project (feature/ttsp-1234/my-first-files)$ git status On branch main Your branch is up to date with 'origin/main'. Changes to be committed: (use "git restore --staged <file>..." to unstage) new file: Makefile new file: hello.c 106 GIT / FILES Adding files
  • 107.  Commit them localy : ~/Workspaces/first-project (feature/ttsp-1234/my-first-files)$ git log commit a97b5e2610097529801eec5a4798f688ed227e5b (HEAD -> main, origin/main, origin/HEAD, integration, hotfix/ttsp-1245/Fix-database- problem, feature/TTSP-27-37/launch-a-vmaf-analysis, develop) Author: Thierry GAYET <thierry.gayet@enensys.com> Date: Thu Apr 13 09:34:27 2023 +0000 Initial commit ~/Workspaces/first-project (feature/ttsp-1234/my-first-files)$ git commit -m "Add the two files" [main d8bc333] Add the two files 2 files changed, 16 insertions(+) create mode 100644 Makefile create mode 100644 hello.c ~/Workspaces/first-project (feature/ttsp-1234/my-first-files)$ git status On branch main Your branch is ahead of 'origin/main' by 1 commit. (use "git push" to publish your local commits) nothing to commit, working tree clean 107 GIT / FILES Commit files
  • 108. ~/Workspaces/first-project (main)$ git log commit d8bc333b8557ab15cd088f7250ebb1f4da31aaa9 (HEAD -> main) Author: Thierry GAYET <Thierry.Gayet@enensys.com> Date: Fri Apr 14 16:36:57 2023 +0200 Add the two files commit a97b5e2610097529801eec5a4798f688ed227e5b (origin/main, origin/HEAD, integration, hotfix/ttsp-1245/Fix-database-problem, feature/TTSP-27-37/launch-a-vmaf-analysis, develop) Author: Thierry GAYET <thierry.gayet@enensys.com> Date: Thu Apr 13 09:34:27 2023 +0000 Initial commit ~/Workspaces/first-project (main)$ git push origin main Enumerating objects: 5, done. Counting objects: 100% (5/5), done. Delta compression using up to 8 threads Compressing objects: 100% (4/4), done. Writing objects: 100% (4/4), 460 bytes | 460.00 KiB/s, done. Total 4 (delta 0), reused 0 (delta 0), pack-reused 0 To gitlab.enensys.com:training/git/first-project.git a97b5e2..d8bc333 main -> main 108 GIT / FILES Push to the gitlab server (aka origin)
  • 109. ~/Workspaces/first-project (feature/ttsp-1234/my-first-files)$ git status On branch main Your branch is up to date with 'origin/main'. nothing to commit, working tree clean ~/Workspaces/first-project (feature/ttsp-1234/my-first-files)$ git rebase main Successfully rebased and updated refs/heads/feature/ttsp-1234/my-first-files. OR ~/Workspaces/first-project (feature/ttsp-1234/my-first-files)$ git rebase main feature/ttsp-1234/my-first-files Current branch feature/ttsp-1234/my-first-files is up to date. ~/Workspaces/training/first-project (feature/ttsp-1234/my-first-files)$ git checkout main Switched to branch 'main' Your branch is up to date with 'origin/main’. ~/Workspaces/training/first-project (main)$ git merge feature/ttsp-1234/my-first-files Already up to date. ~/Workspaces/first-project (main)$ git push origin main 109 GIT / FILES We need to switch to the main branch ! We resynchronize the main branch wit the current one We can resynchronize the main branch with the other one given On the main branch, we merge our feature branch to main Finaly we push the local main branch to gitlab
  • 110. 110 GIT / FILES Now with vscode
  • 111. 111 GIT / FILES We specify the develop branch and valid with ENTER
  • 112. 112 GIT / FILES We fill the new branch’s name and valid with ENTER or cancel with ESCAPE
  • 113. 113 GIT / FILES The branch is correct We can add a file hello.c then Makefile by this way
  • 114. 114 GIT / FILES The two files are well added localy
  • 115. 115 GIT / FILES hello.c is already added Makefile is not added yet We can add it using this icon A mean Added
  • 116. 116 GIT / FILES The two files are added Now we can commit and/or push to the gitlab server
  • 117.  Then we can create Merge request on GITLAB but we will see that later. 117 GIT / FILES
  • 118.  On your develop-USERNAME, add hello.c + Makefile to the project to the GIT project  Commit the files  Push your branch to GITLAB (origin) 118 GIT / FILES  All branches’s name must be in lowercase  just replace USERNAME by your nn6 one !
  • 120.  Worldwide, interest and adoption of DevOps is growing rapidly. But what is DevOps ? 1. DevOps is a set of practices that emphasizes collaboration and communication between software developers and IT operations professionals, automating the process of software delivery and infrastructure changes. 2. The term DevOps was born from the union of “development” and “operations” whose objective is to promote better communication between the two teams. 3. DevOps aims to create a culture and environment in which the design, testing and release of software can be done quickly, frequently and efficiently. DevOps is not just a methodology, it is a real philosophy of work. DEVOPS 120
  • 121.  Benefits of adopting the DevOps approach :  1. Improved quality of code, products and services (reduced bugs, higher change success rate, etc.)  2. Increased efficiency (eg optimization of time spent on activities that create added value: unprecedented added value for the customer)  3. Improved time to market  4. Better alignment between IT and business  5. Smaller versions delivered very quickly and very frequently  6. Improved productivity, customer satisfaction, staff satisfaction  7. Less risk and less backtracking  8. Long-term cost reduction DEVOPS 121
  • 123.  The DevSecOps (Development - Security - Operations) approach is an approach that allows data security to be integrated from the start of a project. The security of these is considered a prerequisite before starting. The goal is to be able to integrate it into the entire project life cycle, from development to implementation, using flexible methods and the DevOps approach.  Integrated into the DevOps process, DevSecOps allows you to configure security test automation every time your application, software, website is tested and deployed. This allows anomalies to be detected and corrected quickly.  The DevSecOps approach involves thinking about the security of your project's applications and infrastructures from the design stage. It is also recommended to automate some tasks regarding data security to avoid slowing down DevOps workflow. To achieve these goals, it is necessary to start by selecting tools that can ensure the continuous integration of security issues, for example, with a common integrated development environment that provides security functionality. However, for DevOps security to be effective, it requires more than new tools. It is necessary to culturally integrate the new security procedures within your teams so that this is implemented and applied as quickly as possible. DEVSECOPS / DEFINITION 123
  • 124.  Benefits of adopting the DevSecOps approach : 1. Security must be integrated from the start of a project (data protection by design) and into the development and implementation processes. In the same way that DevOps automates application deployments, DevSecOps automates security testing. These must be carried out immediately after the first delivery of your project (application, software, etc.). This applies to development, demo, test and pre-production environments. Automated monitoring of the results of these tests will alert relevant teams to vulnerabilities in real time long before the final product reaches the production environment. This process enables early detection of data security gaps and gaps. This allows you to react quickly so that you can deploy a final product that will have far fewer privacy and data security issues. 2. Develop a culture of safety among your employees 3. For the DevSecOps approach to be effective, close cooperation is required between Dev Ops, Operations teams, IT and project stakeholders. Therefore, in order to develop a culture of safety, it is necessary to create an atmosphere of trust between the groups. 4. In order for everyone to feel involved in the cooperation, training and security awareness sessions can be planned. The CIO plays an important role because he has an overview of the project and the teams and allows him to play a transverse role, necessary for the proper functioning of the project. 5. Use of computer security automation tools 6. An effective DevSecOps process is only possible with the right tools. The use of a vulnerability scanner, for example, allows automatic analysis of web applications. This type of tool can be integrated very well into your current operational processes DEVSECOPS 124
  • 130.  The interface of GitLab remains very similar to that of GitHub. However, GitLab offers options that are less practical :  Project management  Planning / prioritization  Build  Software testing  Application Security  Configuration Management  Monitoring  Continuous integration and deployment, etc. GITLAB / INTRODUCTION 130
  • 131.  Structure of GITLAB : GITLAB / 131 GIT REPO Package registry .deb .rpm .tar.gz Docker registry Infrastructure registry (for the deploy using Terraform) GITLAB https://gitlab.enensys.com/help/user/packag es/package_registry/index https://gitlab.enensys.com/help/user/infrast ructure/index git / ssh https RUNNERS CI .gitlabci.yml
  • 133.  GitLab and Docker  Free software Docker launches applications in software containers. For the use of GitLab, its integration makes it possible to automate certain functionalities when sending your source code.  For example, it can perform unit tests, send notifications and install "npm install" type dependencies.  GitLab also has a GitLab agent for the Kubernetes container orchestrator, which allows it to apply its CI/CD pipeline to Kubernetes clusters. GITLAB / DOCKER 133
  • 134.  GitLab API  To benefit from the GitLab API documentation, the company offers online documentation, as well as a search engine to find answers to more specific technical questions.  https://docs.gitlab.com/ee/api/  https://docs.gitlab.com/search/  External build require API TOKENS ! GITLAB / API 134
  • 135.  What is GitLab CI?  GitLab CI/CD is a GitLab tool designed to manage the continuous integration and deployment of application code and revisions. GitLab CI/CD goes through the configuration of a file called .gitlab-ci.yml placed in the root directory. A file that generates a pipeline executing code changes within the code repository. GITLAB / CI 135
  • 136.  GIT WORKFLOW : 136 REMOTE / ORIGIN GITLAB’S SERVER LOCAL YOUR COMPUTER + fetch
  • 137. GITLAB 137 CODE ADD + COMMIT LOCAL CI : LINTERS REMOTE / ORIGIN GITLAB BUILD TEST TAG DEPLOY PUSH main (stable) integration develop (instable)
  • 138.  What is a GitLab Runner?  Gitlab-runner is the application for running tasks in a GitLab CI/CD pipeline.  If installing Gitlab-runner locally, it is recommended to deploy it on a separate machine from the one hosting the GitLab instance, both for performance and security reasons.  Each must be equipped with its own software stack: OS, Kubernetes, Docker... GITLAB / RUNNER 138
  • 139.  Guest : GITLAB / PERMISSIONS 139
  • 140.  Reporter : 140 GITLAB / PERMISSIONS
  • 141.  Developer : 141 GITLAB / PERMISSIONS
  • 142.  Some of the specific actions that the Developer permission role is able to take include:  Create new branches  Remove certain branches  Lock merge request threads  Create, manage, accept, and label merge requests  Create or update a commit status  Delete images from a container registry  Add tags to the issue tracker  Create and edit Wiki pages  Apply code change suggestions  Create, edit, and delete project milestones 142 GITLAB / PERMISSIONS
  • 143.  Maintainer : 143 GITLAB / PERMISSIONS
  • 144.  The Maintainer role can take all the actions allowed in the Developer role, as well as actions including:  Add new members to the project  Determine write protection status for branches  Determine write protection status for pushes to branches  Edit the settings for the project  Configure project hooks  Manage job triggers  Manage runners  Manage environmental variables  Manage domains  Manage certificates  Manage and delete GitLab Pages  Edit comments that any user posts  Delete Wiki pages 144 GITLAB / PERMISSIONS
  • 145.  Owner : 145 GITLAB / PERMISSIONS https://nira.com/gitlab-permissions/#:~:text=The%20Owner%20role%20is%20the,to%20nearly%20all%20projects'%20actions.
  • 146. Create a new project
  • 147.  To create a new git repo, we need to be in the right group  Each git repo have its own :  Docker registry  Package registry  Infrastructure registry  CI / CD pipeline (.gitlabci.yml file)  WIKI  Settings 147 GITLAB / CREATE
  • 150. GITLAB / CREATE 150 Name of the new GIT repo NN6 base URL Option for the repo Visibility Namespace Name of the repo Validate with create project  For the new repo : Base URL : https://gitlab.enensys.com/ Namespace : training/gitlab Project’s name : my-second-project Final GIT url : GIT git@gitlab.enensys.com:training/gitlab/my-second-project.git Final https url : https://gitlab.enensys.com/training/gitlab/my-second-project.git
  • 151.  When we have always the same namespace, we can set/use groups : 151 GITLAB / CREATE
  • 152. 152 GITLAB / CREATE  If you don’t have access to some groups, you can send an email to helpdesk@enensys.com
  • 153. GITLAB /CREATE 153  After few seconds, Gitlab has create the GIT repo
  • 154. GITLAB / CREATE 154 Identity Last commit message / SHA1 URLs for the clone Links to open in VS code or others IDE First file Quick shortcuts Default’s branch Summary
  • 155. 155  Create a private git repo called « myrepo- USERNAME » inside the traning/gitlab namespace (https://gitlab.enensys.com/training/gitlab)  Create all the branches according to the gitflow (using VSCODE and/or GITLAB)  Check that the default’s branch is main  Restrict any direct push to main, intégration and develop  Add one hello.c and Makefile files  Add a .gitignore file (filled with https://www.toptal.com/developers/gitignore)  Add, commit and push all to GITLAB  All branches’s name must be in lowercase  just replace USERNAME by your nn6 one ! GITLAB / CREATE
  • 156. INSPECT THE PROJECT (LEFT SIDEBAR)
  • 157.  The following slides will be usefull to customize a new repo but also an existing one.  We will see step by step what is to customize… 157 GITLAB / INFO
  • 160. GITLAB / INFO 160 People that have right to the git repo Role
  • 161. GITLAB / REPO. 161 The following files or directories can only be modified by the user who locked them. To see what's changed or create a merge request, choose a branch or tag (like main ), or enter a commit (like 4eedf23 ). Changes are shown as if the source revision was being merged into the target revision. Display a graph of the commits by branch Stats of commits by users Create/List/Delete Tags for the releases List of the files per branch List of the commits per branch Create/List/Branches
  • 162. GITLAB / REPO. / GRAPH 162  Example ot GIT repository with no branches (very flat) !
  • 163. 163 GITLAB / REPO. / GRAPH  Example of GIT repository with branches
  • 164. GITLAB / REPO. / BRANCHES 164
  • 165. GITLAB / REPO. / BRANCHES 165
  • 166. GITLAB / REPO. / BRANCHES 166 Default’s branch
  • 167. GITLAB / ISSUES 167 Not use at NN6 ; similar to JIRA as a bug tracker !
  • 168.  Merge request can be used for :  Code review  Share code between team members  Validate modification from one branch to another one  feature or bugfix branches  develop’s branch  develop’s branch  integration’s branch  integration’s branch  main’s branch Only if the hotfix is cleaned :  hotfix’s branch  integration’s branch  Integration’s branch to develop’s branch  MR workflow : 168 GITLAB / Merge Request Creation Validation Merge Destroy source’s branch
  • 169. GITLAB / Merge Request 169 Workflow :  A developer has finished developing a feature / a bugfix and asks to merge his code to the develop branch  He makes a merge request to one or more of his colleagues  One of his colleagues makes a remark to him that he must take into account  After modification resulting from the remark, a new push is carried out with the same Merge Request  This time, the MR is validated  Then, the code can be merged  If the branch’s destruction request has been selected, it will be destroyed
  • 170. 170 GITLAB / Merge Request Name of the repo Branch’s source Destination’s branch Select this button to compare the two branches
  • 171. 171 GITLAB / Merge Request One or more reviewer Just a comment on what i am merging Name of the merge (feature’s name, what is fixed, …)
  • 172. 172 GITLAB / Merge Request Delete the (feature/bugfix/hotfix/…) branch after the merge request Proceed to the MR  Each reviewer will receive an email that will notify them about the MR Commit(s) impact with this merge request
  • 173. 173 GITLAB / Merge Request Checkout, edit the branch from gitlab Number of merge request associated to me We can valid the MR or not We can add a comment for the develop that describe why we cannot valid the MR If we are okay with the MR we can launch the Merge
  • 174. 174  Create new feature branch (from develop) using the gitflow (idJIRA=TTSP-1235 / Description=« Mys first feature »)  Add new test.c + test.h (fake) file to the repo.  Add+commit them to the branch  Push to your branch  (GITLAB) Make a MR from the feature’s branch to the develop’s branch  Add comment to your MR  Accept and merge your MR  Watch the result on gitlab  All branches’s name must be in lowercase  just replace USERNAME by your nn6 one ! GITLAB / SETTINGS
  • 175.  CI - Continuous Integration : this is useful for …  Launching linters (coding style checkerker : cppchecker, pylint, … )  Building the service/component  Launching unit tests (with address sanatizer in c++)  Generating automatic documentation (eg: doxygen)  Creating docker, deb/rpm/… packages, tarballs, ...  Building a buildroot firmware  Creating a VM using Hashicorp packer 175 GITLAB / CI/CD
  • 176.  CD – Continuous Delivery : this is useful for …  Adding tag to a docker  Pushing a docker to a docker’s registry according to the branch (one registry per branch : develop, integration, main)  Pushing a rpm/deb/tarball to the package’s registry  Pushing helm charts to a kubernetes (k8s)  Deploying images created with packer using Hashicorp Terraform 176 GITLAB / CI/CD
  • 177. 177 GITLAB / CI/CD Gitlab bring a lot of templates … / …  The goal of those template will be to add a ..gitlab-ci.yml adapt to a language
  • 178. 178
  • 179. 179 GITLAB / CI/CD # This file is a template, and might need editing before it works on your project. # You can copy and paste this template into a new `.gitlab-ci.yml` file. # You should not add this template to an existing `.gitlab-ci.yml` file by using the `include:` keyword. # # To contribute improvements to CI/CD templates, please follow the Development guide at: # https://docs.gitlab.com/ee/development/cicd/templates.html # This specific template is located at: # https://gitlab.com/gitlab-org/gitlab/-/blob/master/lib/gitlab/ci/templates/C++.gitlab-ci.yml # use the official gcc image, based on debian # can use versions as well, like gcc:5.2 # see https://hub.docker.com/_/gcc/ image: gcc build: stage: build # instead of calling g++ directly you can also use some build toolkit like make # install the necessary build tools when needed # before_script: # - apt update && apt -y install make autoconf script: - g++ helloworld.cpp -o mybinary Docker image that include gcc  Because the image is a docker file, we can use our image or customize the origginal’s one !
  • 180. 180 artifacts: paths: - mybinary # depending on your build setup it's most likely a good idea to cache outputs to reduce the build time # cache: # paths: # - "*.o" # run tests using the binary built before test: stage: test script: - ./runmytests.sh deploy: stage: deploy script: echo "Define your deployment script!" environment: production GITLAB / CI/CD
  • 181. 181 GITLAB / CI/CD Email received from gitlab that inform us that the pipeline has failled !
  • 182.  Anothe usefull pipeline : image: gitlab.enensys.com:4567/tm-testtree/monitor/streamprobe/streamprobe/codequality:latest stages: - cppcheck - sonar quality:cppcheck: stage: cppcheck script: - ./ci/analysis-cppcheck.sh artifacts: name: pages when: always paths: - cppcheck/ - sonar-project.properties - streamprobe-cppcheck.xml 182 quality:sonar: stage: sonar dependencies: - quality:cppcheck artifacts: name: sonar expire_in: 1 day paths: - sonar.log script: - sonar-scanner -X > sonar.log GITLAB / CI/CD
  • 183.  Sometime pipeline can ask some secret at the CI and/or CD stage : 183 GITLAB / CI/CD Secrets  No secrets must be as is int CI/CD scripts !
  • 184.  Settings / CI/CD / Variables Usefull to rename a project or to move it from one namespace to another one : 184 GITLAB / CI/CD
  • 185.  Adding a new secret : 185 GITLAB / CI/CD It can be a variable or a file
  • 186. 186 GITLAB / CI/CD History of previous launch
  • 187. 187 GITLAB / CI/CD Two step/stages wit our pipeline
  • 188.  Example of pipeline (ci) will do what you want it to do : 188 LINTERS : cppcheck, pylint, dockerlint, … BUILD UNITTEST API DOCUMENTATION (doxygen)  If one step is wrong, the pipeline will stop and send one email. GITLAB / CI/CD Create docker image …  The earlier a test is carried out, the faster the problems are handled because it tells the developer that something is not compliant and thus avoids waiting for functional integration tests
  • 189.  Example of pipeline (cd) will do what you want it to do : 189 Tag a docker image Login to the registry Push a docker image to t he registry Launch automatic tests  If one step is wrong, the pipeline will stop and send one email.  For security purpose, all push in production (main branch) MUST be manual ! GITLAB / CI/CD …
  • 190. 190 Running (now or previously) can be viewed here We can see the exécution’s trace of the pipeline (see on, next slide) GITLAB / CI/CD
  • 191. 191  If one pipeline failled, the traces are very usefull to know the origin of the problem.
  • 192. 192 GITLAB / CI/CD  This is possible to launch CI pipeline every nigtht, in order to have a sanity check on one repo, on a specific branch, …
  • 193.  We can work (update) the dockers launch for the pipelines : $ docker login gitlab.enensys.com:4567 Username: gayett Password: WARNING! Your password will be stored unencrypted in /home/ubuntu/.docker/config.json. Configure a credential helper to remove this warning. See https://docs.docker.com/engine/reference/commandline/login/#credentials-store Login Succeeded  Now we can pull / update and push our docker image that host binaries useful for our unit test, linters and co …. 193 GITLAB / CI/CD
  • 194. 194 GITLAB / Packages and registries  Gitlab can manage :  Container registry : o Docker images  Package registry : o debian (deb) o redhat packages (RPM) o tarballs (ZIP, tar.gz, ….)  Infractructure registry : o final images or firwmwares (to deploy)  and more …
  • 195. 195 GITLAB / Wiki  Each git repo has his own (separated) wiki !
  • 196.  At any time this is possible to modify the settings of a specify repo  For security purpose, only maintainers or owners can modify it. 196 GITLAB / Settings
  • 198.  Settings / General / Advanced / Change path Usefull to rename a project or to move it from one namespace to another one : 198
  • 199.  Settings / Integration Gitlab can be linked with external tools : 199 GITLAB / Settings
  • 200.  Settings / Repository Define main branch at the clone time : 200 GITLAB / Settings
  • 201.  Settings / Repository / branch default Specify a pattern as a regexp for branch’s name 201 GITLAB / Settings
  • 202.  Settings / Repository / protected branches Avoid any direct push to main/integration/develop (must use MR) 202 GITLAB / Settings
  • 203.  Integration with JIRA in order to push SHA1 commit to User Story :  https://about.gitlab.com/blog/2021/04/12/gitlab-jira-integration- selfmanaged/ 203 GITLAB / Settings
  • 204. 204  Create a .gitlabci.yaml file from scrach or using a template)  Make it work and run it  If you have time, customize a docker image, add tools and push it back to the gitlab docker’s registry.  All branches’s name must be in lowercase  just replace USERNAME by your nn6 one ! GITLAB / SETTINGS
  • 206. Stash
  • 207.  Because it is not possible to switch to another branch until the current branch has committed everything, git proposes the use of an area called stash which allows to save modifications which can be re- imported by the following : $ git stash  We backup our current work (on branch XXX) $ git checkout main (do something here) $ git add files … $ git commit –m “urgent modification” $ git push origin main $ git checkout XXX $ git stash list $ git stash pop  here we can continue on our previous work GIT / STASH 207
  • 208. GIT / STASH 208 Now with vscode
  • 209. 209  Add several files (as you want)  Try to swicth to another branch  (You should have a problem here)  Now, stash your current work  Switch to a branch (Here we can make something urgent)  Got back to you previous branch  List the stash wor  Pop your last work (Now we can continue to work)  All branches’s name must be in lowercase  just replace USERNAME by your nn6 one ! GITLAB / STASH
  • 210. LFS aka Large File System
  • 211.  In order to avoid overloading a git repo with large files which would ultimately take a long time to clone, git lfs is very useful because it allows large files to be separated into a separate channel from the usual clone.  For that purpose, you must have the git-lfs client installed on your system.  https://docs.gitlab.com/ee/topics/git/lfs/  https://docs.gitlab.com/ee/user/project/settings/index.html#configur e-project-visibility-features-and-permissions GIT / LFS 211 GITLAB (GIT) LFS
  • 212.  Your gitlab projet must be enabled for that feature : 212 GIT / LFS
  • 213.  Add filter to git repo for some extension to be managed by git lfs :  Download and install the Git command line extension.  Once downloaded and installed, set up Git LFS for your user account by running: $ git lfs install  You only need to run this once per user git user account. In each Git repository where you want to use Git LFS, select the file types you'd like Git LFS to manage (or directly edit your .gitattributes).  You can configure additional file extensions at anytime. $ git lfs track "*.psd"  Now make sure .gitattributes is tracked: $ git add .gitattributes $ git commit –m “add lfs filtering for psd files” $ git push origin main 213 GIT / LFS
  • 214.  Note that defining the file types Git LFS should track will not, by itself, convert any pre-existing files to Git LFS, such as files on other branches or in your prior commit history. To do that, use the git lfs migrate command, which has a range of options designed to suit various potential use cases.  As a test, just commit and push to gitlab as you normally would ; for instance, if your current branch is named main: $ git add file.psd $ git commit -m "Add photoshop design file" $ git push origin main A “git lfs status” command will show you all files managed by git and that will be pushed to gitlab by this way. 214 GIT / LFS
  • 215.  For existing git repo, this is possible to cleanup using bfg :  First clone a fresh copy of your repo, using the --mirror flag : $ git clone --mirror git@gitlab.enensys.com:training/git/some-big-repo.git  This is a bare repo, which means your normal files won't be visible, but it is a full copy of the Git database of your repository, and at this point you should make a backup of it to ensure you don't lose anything.  Now you can run the BFG to clean your repository up: $ wget https://repo1.maven.org/maven2/com/madgag/bfg/1.14.0/bfg-1.14.0.jar $ java -jar ./bfg-1.14.0.jar --strip-blobs-bigger-than 100M some-big-repo.git  The BFG will update your commits and all branches and tags so they are clean, but it doesn't physically delete the unwanted stuff. Examine the repo to make sure your history has been updated, and then use the standard git gc command to strip out the unwanted dirty data, which Git will now recognise as surplus to requirements: $ cd some-big-repo.git && git reflog expire --expire=now --all && git gc --prune=now --aggressive  Finally, once you're happy with the updated state of your repo, push it back up (note that because your clone command used the --mirror flag, this push will update all refs on your remote server) : $ git push  Official repo : https://rtyley.github.io/bfg-repo-cleaner/ 215 GIT / LFS
  • 216. 216 GIT / LFS Now with vscode https://github.com/microsoft/vscode-dev-containers/blob/main/script- library/docs/git-lfs.md
  • 217. 217  Enable LFS setting on your git repo (GITLAB)  Check you have git lfs install on your system  Add GIT lfs support to your repo  Check the .gitattributes file and add/commit it  Add a filter with *.mp4 and *.ts files  Add a ts file and check the file is well tracked using git-lfs status  Push all to gitlab and check what is managed over LFS  Try to clone you repo in a /tmp directory, just to check everything.  All branches’s name must be in lowercase  just replace USERNAME by your nn6 one ! GITLAB / LFS
  • 219.  Imagine a part of git repo that could be factored between several other repos such as a submodule that would be attached.  To do this, git sub-modules were invented to allow you to link a repo  Create a git repo that will be linked  Add the repo to each repo that will need to be linked  Commit and push the .gitmodules file and the folder of the submodule itself GIT / SUBMODULE 219 GIT REPO FACTORIZED GIT REPO A GIT REPO B
  • 220.  Immagine you are inside a repo git already cloned. You can add the fatorized repo like this : ~/Workspaces/first-project (develop)$ git submodule add git@gitlab.enensys.com:training/git/DbConnector Cloning into 'DbConnector'... remote: Counting objects: 11, done. remote: Compressing objects: 100% (10/10), done. remote: Total 11 (delta 0), reused 11 (delta 0) Unpacking objects: 100% (11/11), done. Checking connectivity... done. By default, submodules will add the subproject into a directory named the same as the repository, in this case “DbConnector”. GIT / SUBMODULE 220
  • 221.  If you run git status at this point, you’ll notice a few things. ~/Workspaces/first-project (develop)$ git status On branch master Your branch is up-to-date with 'origin/master'. Changes to be committed: (use "git reset HEAD <file>..." to unstage) new file: .gitmodules new file: DbConnector  First you should notice the new .gitmodules file. This is a configuration file that stores the mapping between the project’s URL and the local subdirectory you’ve pulled it into: [submodule "DbConnector"] path = DbConnector url = git@gitlab.enensys.com:training/git/DbConnector  If you have multiple submodules, you’ll have multiple entries in this file. It’s important to note that this file is version- controlled with your other files, like your .gitignore file.  It’s pushed and pulled with the rest of your project. This is how other people who clone this project know where to get the submodule projects from. 221 GIT / SUBMODULE
  • 222.  Don’t forget to commit and push the .gitmodules file and the repo that host the factorized git repo : ~/Workspaces/first-project (develop)$ git commit -am 'Add DbConnector module' [master fb9093c] Add DbConnector module 2 files changed, 4 insertions(+) create mode 100644 .gitmodules create mode 160000 DbConnector Notice the 160000 mode for the DbConnector entry. That is a special mode in Git that basically means you’re recording a commit as a directory entry rather than a subdirectory or a file.  To update the revision of a submodule within a git repo, you can just enter into the submodule folder, then switch to a new sha1, tag or branch of the submodule. Then got back at the root path of the repo that host the git submodule and just commit the folder.  Lastly, push these changes: ~/Workspaces/first-project (develop)$ git push origin master 222 GIT / SUBMODULE
  • 223.  When cloning a repo, the .gitmodules is pull with the other files but the folder of each submodule are empty.  To initialise the folder we can use the following commands :  ~/Workspaces/first-project (develop)$ git submodule init  ~/Workspaces/first-project (develop)$ git submodule update  To clone and initialize each submodule, you can do it that way :  ~/Workspaces/first-project (develop)$ git clone --recurse-submodules git@gitlab.enensys.com:training/git/first-project.git 223 GIT / SUBMODULE
  • 224. GIT / SUBMODULE 224 Now with vscode https://marketplace.visualstudio.com/items?itemName=ivanhofer.git- assistant#:~:text='Git%20(Submodule)%20Assistant',and%20assists%20yo u%20with%20fixes.
  • 225. 225  Clone the repo « my-first-project » from the HEAD as a submodule https://gitlab.enensys.com/training/git/first- project  Watch the .gitmodules file  Add the .gitmodules file and the folder of the repo cloned  Commit and push all to gitlab  All branches’s name must be in lowercase  just replace USERNAME by your nn6 one ! GITLAB / SUBMODULES
  • 226. MORE HELP ABOUT GIT 226
  • 227.  LINKS : o https://git-scm.com/doc o https://git-scm.com/docs o https://git-scm.com/book/en/v2 o https://git-scm.com/doc/ext o https://git-scm.com/docs/gittutorial o https://gitimmersion.com/ o https://github.com/sensorflo/git-draw/wiki o http://www-cs-students.stanford.edu/~blynn/gitmagic/ o https://git-scm.com/docs/giteveryday o https://nulab.com/learn/software-development/git-tutorial/git-basics/ o https://github.com/progit/progit2-fr/releases/download/2.1.70/progit.pdf o https://github.com/progit/progit2/releases/download/2.1.360/progit.pdf https://www.amazon.fr/s?k=git&i=stripbooks&__mk_fr_FR=%C3%85M%C3%85%C5%BD%C3%95%C3%91&crid=424VPI44G9P 5&sprefix=git%2Cstripbooks%2C105&ref=nb_sb_noss_1 GIT / HELP 227 (Official printed documentation)
  • 228. 228
  • 229.  If you want to go more in detail about dev(sec)ops automations, I can do a third training specific to CI/CI chain-oriented CI, to build a docker image, push a helm chart into a kubernetes, build a buildroot image / yocto, ...... gitlab can do everything :-)! MORE 229
  • 230. Next part, the NN6 official : gitflow, versionning and svn migration. 230
  • 231. ENENSYS 4A rue des Buttes CS 37734 35 577 Cesson-Sévigné – France Phone (+33) 1 70 72 51 70 Email contact@test-tree.com www.enensys.com 231