SlideShare a Scribd company logo
Introduction to Git and
GitLab
15 May. 2019 | P. Weidenkaff | Introduction to Git and GitLab 0
Pictures from www.atlassian.com/git/tutorials
Slides at https://indico.him.uni-mainz.de/event/37/
What is a Version Control System (VCS)?
• Track changes among (any type of) files
• Long term history of changes
• Collaborate on files (e.g. source code)
• Answer: Who ? Why ? When ?
15 May. 2019 | P. Weidenkaff | Introduction to Git and GitLab 1
Advantages of Git
• Distributed VCS
• Every user keeps the full set of changes
• Independent of network connection or central server
• Easy collaboration on code via pull/merge requests
• Forking of projects
• Became very popular is combination with web interfaces
GitLab, GitHub, Bitbucket
Pictures from www.atlassian.com/git/tutorials
Slides at https://indico.him.uni-mainz.de/event/37/
Getting started - git init/add/commit
• Getting help
man git
man git-<subcommand>, e.g. man git-add
• Initialize a new repository
git init
• Create file or add existing ones
git add testfile
git add *.cxx
• First commit
git commit –a –m “Initial commit”
git commit --amend
• Further changes – show differences
git status
git diff
• Exclude files using .gitignore
15 May. 2019 | P. Weidenkaff | Introduction to Git and GitLab 2
Inspecting a repository - git log/diff/blame
• Inspect commit history
git log
git log --oneline
• Write proper log messages!
• Show changes since some commit
git diff HEAD~3
git diff f44596f
git diff f44596f827263d90cb52fe10c3104bd8cce742bc
git diff HEAD~3 -- README.rst
• Show who’s responsible for a certain line of code
git blame README.rst (Use the IDE of your choice)
15 May. 2019 | P. Weidenkaff | Introduction to Git and GitLab 3
Fix mistakes - git checkout/reset/revert
• Fix your mistakes – copy file from previous commit
git checkout HEAD -- README.rst
• Reset all changes to HEAD
git reset --hard HEAD
• Revert the changes of a single commit
git revert HEAD~3
15 May. 2019 | P. Weidenkaff | Introduction to Git and GitLab 4
Branches - git branch/clone
• List branches
git branch (-a)
• Create a new branch
git branch new
git checkout new
• Clone remote repository
git clone https://git....
git clone git@git....
git clone /local/path/to/repo
• Merge branches (new into master)
git checkout new
git merge master
• Remote repositories
git remote –v
git remote add/remove
15 May. 2019 | P. Weidenkaff | Introduction to Git and GitLab 5
git checkout -b new
Exercise I
I. Create a repository, add files, commit
II. Get repository
git@gitlab.rlp.net:
git-introduction/example-multibranch.git
OR:
https://gitlab.rlp.net/
git-introduction/example-multibranch.git
1. Show all (remote) branches
2. Pull remote branch new:
git checkout origin/new
3. Merge branch new into master
4. Open the conflicting file and solve the merge conflict
5. Commit and push your changes
6. Check the history using
git log --oneline --graph --decorate
(or use some graphical tool like gitk)
15 May. 2019 | P. Weidenkaff | Introduction to Git and GitLab 6
Collaborating on git repositories - GitLab
• Public services www.gitlab.com
www.github.com
• University hosted service gitlab.rlp.com
• Web interface to many git functions
• Access management to the repository
• Management of bug reports (Issues)
• Code analysis
• Provides releases
• Wiki pages
• Continuous integration (CI)
• Backup and long time storage
15 May. 2019 | P. Weidenkaff | Introduction to Git and GitLab 7
Exercise II
I. Create a repository on gitlab.rlp.net
1. Use an existing project and initialize a git repository
2. Add a new remote to your existing repository
git remote add origin git@gitlab.rlp.net:
git-introduction/example-multibranch.git
3. Push your repository to GitLab
II. Fork an existing repository in GitLab
https://gitlab.rlp.net/git-introduction/example-multibranch.git
1. Clone the fork
2. Perform a change and push it to your fork
3. Create a merge request (pull request) on GitLab
15 May. 2019 | P. Weidenkaff | Introduction to Git and GitLab 8
Advanced topics
Submodules
Large file support
Continuous integration
15 May. 2019 | P. Weidenkaff | Introduction to Git and GitLab 9
Submodules – git submodule
• Modular organization of my own code
• Dependency of (fast) changing code
• Avoid another system dependency
• Software typically not available on all Unix systems
• Add submodule
git submodule add git@gitlab.rlp.net:...
• Clone respository with submodules
git clone [URL]
git submodule init
git submodule update
• Update submodules
git submodule update --remote
15 May. 2019 | P. Weidenkaff | Introduction to Git and GitLab 10
git clone
--recursive [URL]
Large file support – git lfs
• Size of the repository matters
• Each clone copies every version of every files ever existed
within the repository
• Problem with large files that change frequently
• Full histroy is not necessary for e.g. pictures, ROOT files
• lfs only downloads versions referenced by current
commit
• Mark such files as lfs:
git lfs install
git lfs
• Download a repository with lfs
git clone [URL]
• Downloaded during git checkout (not git clone)
15 May. 2019 | P. Weidenkaff | Introduction to Git and GitLab 11
Continuous integration (CI)
• Verify each commit
• Build code (on several systems)
• Run tests
• ThirdParty tools on code quality
• Configure on GitLab via
.gitlab-ci.yml
• Images available on
https://hub.docker.com/
• Templates are provided
on GitLab
15 May. 2019 | P. Weidenkaff | Introduction to Git and GitLab 12
image: gcc
build:
stage: build
before_script:
- apt update && 
apt -y install make
script:
- g++ helloworld.cpp 
-o mybinary
artifacts:
paths:
- mybinary
test:
stage: test
script:
- ./runmytests.sh
Exercise II
I. Submodules
1. Clone including submodules
https://github.com/ComPWA/ComPWA.git
2. Update submodules
II. LFS
1. Use a custom project and add some files to be tracked via lfs
2. Push the repository to GitLab
III. CI
1. Create a repository and add a LaTeX document
2. Upload it to gitlab
3. Setup CI to recreate the document every time the repository is
updated
15 May. 2019 | P. Weidenkaff | Introduction to Git and GitLab 13
Summary
Git and GitLab
• Git tracks changes in your
code (or other files)
• GitLab organizes
collaboration on Code
• Issues
• Merge requests
• Access control
There is more....
• Advanced git commands
git rebase/bisect
• Filetypes different from pure
text
Word, TeX, jupyter notebooks
• GitLab Docker registry to store
images generated by CI
15 May. 2019 | P. Weidenkaff | Introduction to Git and GitLab 14
Ad

More Related Content

Similar to Git_Git_Lab_1664715263.pdf (20)

Beginner's Guide to Version Control with Git
Beginner's Guide to Version Control with GitBeginner's Guide to Version Control with Git
Beginner's Guide to Version Control with Git
Robert Lee-Cann
 
ePOM - Fundamentals of Research Software Development - Code Version Control
ePOM - Fundamentals of Research Software Development - Code Version ControlePOM - Fundamentals of Research Software Development - Code Version Control
ePOM - Fundamentals of Research Software Development - Code Version Control
Giuseppe Masetti
 
tech winter break workshop on git &git hub.pptx
tech winter break workshop on git &git hub.pptxtech winter break workshop on git &git hub.pptx
tech winter break workshop on git &git hub.pptx
ashishraulin
 
Git hub visualstudiocode
Git hub visualstudiocodeGit hub visualstudiocode
Git hub visualstudiocode
Rolands Krumbergs
 
Git for uninitiated
Git for uninitiatedGit for uninitiated
Git for uninitiated
John C. Chan
 
Open up your platform with Open Source and GitHub
Open up your platform with Open Source and GitHubOpen up your platform with Open Source and GitHub
Open up your platform with Open Source and GitHub
Scott Graham
 
Introduction to git
Introduction to gitIntroduction to git
Introduction to git
Nguyen Van Hung
 
Git, GitHub and Open Source
Git, GitHub and Open SourceGit, GitHub and Open Source
Git, GitHub and Open Source
Lorna Mitchell
 
Let's Git this Party Started: An Introduction to Git and GitHub
Let's Git this Party Started: An Introduction to Git and GitHubLet's Git this Party Started: An Introduction to Git and GitHub
Let's Git this Party Started: An Introduction to Git and GitHub
Kim Moir
 
GitHub Event.pptx
GitHub Event.pptxGitHub Event.pptx
GitHub Event.pptx
KeerthanaJ32
 
GIT-FirstPart.ppt
GIT-FirstPart.pptGIT-FirstPart.ppt
GIT-FirstPart.ppt
ssusered2ec2
 
Git and Github and how can we leverage in Daily Coding
Git and Github and how can we leverage in Daily CodingGit and Github and how can we leverage in Daily Coding
Git and Github and how can we leverage in Daily Coding
wrdxtevhxiseyweuiw
 
Git workshop
Git workshopGit workshop
Git workshop
Reslan Al Tinawi
 
3 Git
3 Git3 Git
3 Git
Fabio Fumarola
 
GitHub_For_Beginners_Presentationss.pptx
GitHub_For_Beginners_Presentationss.pptxGitHub_For_Beginners_Presentationss.pptx
GitHub_For_Beginners_Presentationss.pptx
ramyagirish78
 
Introduction to git and githhub with practicals.pptx
Introduction to git and githhub with practicals.pptxIntroduction to git and githhub with practicals.pptx
Introduction to git and githhub with practicals.pptx
Abdul Salam
 
Version Control Systems Software Engineering
Version Control Systems Software EngineeringVersion Control Systems Software Engineering
Version Control Systems Software Engineering
ssuser1c86e3
 
Git tutorial
Git tutorialGit tutorial
Git tutorial
Peder Larson
 
Git is a distributed version control system .
Git is a distributed version control system .Git is a distributed version control system .
Git is a distributed version control system .
HELLOWorld889594
 
Git installation and configuration
Git installation and configurationGit installation and configuration
Git installation and configuration
Kishor Kumar
 
Beginner's Guide to Version Control with Git
Beginner's Guide to Version Control with GitBeginner's Guide to Version Control with Git
Beginner's Guide to Version Control with Git
Robert Lee-Cann
 
ePOM - Fundamentals of Research Software Development - Code Version Control
ePOM - Fundamentals of Research Software Development - Code Version ControlePOM - Fundamentals of Research Software Development - Code Version Control
ePOM - Fundamentals of Research Software Development - Code Version Control
Giuseppe Masetti
 
tech winter break workshop on git &git hub.pptx
tech winter break workshop on git &git hub.pptxtech winter break workshop on git &git hub.pptx
tech winter break workshop on git &git hub.pptx
ashishraulin
 
Git for uninitiated
Git for uninitiatedGit for uninitiated
Git for uninitiated
John C. Chan
 
Open up your platform with Open Source and GitHub
Open up your platform with Open Source and GitHubOpen up your platform with Open Source and GitHub
Open up your platform with Open Source and GitHub
Scott Graham
 
Git, GitHub and Open Source
Git, GitHub and Open SourceGit, GitHub and Open Source
Git, GitHub and Open Source
Lorna Mitchell
 
Let's Git this Party Started: An Introduction to Git and GitHub
Let's Git this Party Started: An Introduction to Git and GitHubLet's Git this Party Started: An Introduction to Git and GitHub
Let's Git this Party Started: An Introduction to Git and GitHub
Kim Moir
 
Git and Github and how can we leverage in Daily Coding
Git and Github and how can we leverage in Daily CodingGit and Github and how can we leverage in Daily Coding
Git and Github and how can we leverage in Daily Coding
wrdxtevhxiseyweuiw
 
GitHub_For_Beginners_Presentationss.pptx
GitHub_For_Beginners_Presentationss.pptxGitHub_For_Beginners_Presentationss.pptx
GitHub_For_Beginners_Presentationss.pptx
ramyagirish78
 
Introduction to git and githhub with practicals.pptx
Introduction to git and githhub with practicals.pptxIntroduction to git and githhub with practicals.pptx
Introduction to git and githhub with practicals.pptx
Abdul Salam
 
Version Control Systems Software Engineering
Version Control Systems Software EngineeringVersion Control Systems Software Engineering
Version Control Systems Software Engineering
ssuser1c86e3
 
Git is a distributed version control system .
Git is a distributed version control system .Git is a distributed version control system .
Git is a distributed version control system .
HELLOWorld889594
 
Git installation and configuration
Git installation and configurationGit installation and configuration
Git installation and configuration
Kishor Kumar
 

Recently uploaded (20)

VKS-Python Basics for Beginners and advance.pptx
VKS-Python Basics for Beginners and advance.pptxVKS-Python Basics for Beginners and advance.pptx
VKS-Python Basics for Beginners and advance.pptx
Vinod Srivastava
 
Thingyan is now a global treasure! See how people around the world are search...
Thingyan is now a global treasure! See how people around the world are search...Thingyan is now a global treasure! See how people around the world are search...
Thingyan is now a global treasure! See how people around the world are search...
Pixellion
 
computer organization and assembly language.docx
computer organization and assembly language.docxcomputer organization and assembly language.docx
computer organization and assembly language.docx
alisoftwareengineer1
 
How iCode cybertech Helped Me Recover My Lost Funds
How iCode cybertech Helped Me Recover My Lost FundsHow iCode cybertech Helped Me Recover My Lost Funds
How iCode cybertech Helped Me Recover My Lost Funds
ireneschmid345
 
How to join illuminati Agent in uganda call+256776963507/0741506136
How to join illuminati Agent in uganda call+256776963507/0741506136How to join illuminati Agent in uganda call+256776963507/0741506136
How to join illuminati Agent in uganda call+256776963507/0741506136
illuminati Agent uganda call+256776963507/0741506136
 
Ppt. Nikhil.pptxnshwuudgcudisisshvehsjks
Ppt. Nikhil.pptxnshwuudgcudisisshvehsjksPpt. Nikhil.pptxnshwuudgcudisisshvehsjks
Ppt. Nikhil.pptxnshwuudgcudisisshvehsjks
panchariyasahil
 
Template_A3nnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnn
Template_A3nnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnTemplate_A3nnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnn
Template_A3nnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnn
cegiver630
 
Principles of information security Chapter 5.ppt
Principles of information security Chapter 5.pptPrinciples of information security Chapter 5.ppt
Principles of information security Chapter 5.ppt
EstherBaguma
 
Cleaned_Lecture 6666666_Simulation_I.pdf
Cleaned_Lecture 6666666_Simulation_I.pdfCleaned_Lecture 6666666_Simulation_I.pdf
Cleaned_Lecture 6666666_Simulation_I.pdf
alcinialbob1234
 
Geometry maths presentation for begginers
Geometry maths presentation for begginersGeometry maths presentation for begginers
Geometry maths presentation for begginers
zrjacob283
 
Digilocker under workingProcess Flow.pptx
Digilocker  under workingProcess Flow.pptxDigilocker  under workingProcess Flow.pptx
Digilocker under workingProcess Flow.pptx
satnamsadguru491
 
Flip flop presenation-Presented By Mubahir khan.pptx
Flip flop presenation-Presented By Mubahir khan.pptxFlip flop presenation-Presented By Mubahir khan.pptx
Flip flop presenation-Presented By Mubahir khan.pptx
mubashirkhan45461
 
Perencanaan Pengendalian-Proyek-Konstruksi-MS-PROJECT.pptx
Perencanaan Pengendalian-Proyek-Konstruksi-MS-PROJECT.pptxPerencanaan Pengendalian-Proyek-Konstruksi-MS-PROJECT.pptx
Perencanaan Pengendalian-Proyek-Konstruksi-MS-PROJECT.pptx
PareaRusan
 
Medical Dataset including visualizations
Medical Dataset including visualizationsMedical Dataset including visualizations
Medical Dataset including visualizations
vishrut8750588758
 
Defense Against LLM Scheming 2025_04_28.pptx
Defense Against LLM Scheming 2025_04_28.pptxDefense Against LLM Scheming 2025_04_28.pptx
Defense Against LLM Scheming 2025_04_28.pptx
Greg Makowski
 
Data Analytics Overview and its applications
Data Analytics Overview and its applicationsData Analytics Overview and its applications
Data Analytics Overview and its applications
JanmejayaMishra7
 
Safety Innovation in Mt. Vernon A Westchester County Model for New Rochelle a...
Safety Innovation in Mt. Vernon A Westchester County Model for New Rochelle a...Safety Innovation in Mt. Vernon A Westchester County Model for New Rochelle a...
Safety Innovation in Mt. Vernon A Westchester County Model for New Rochelle a...
James Francis Paradigm Asset Management
 
FPET_Implementation_2_MA to 360 Engage Direct.pptx
FPET_Implementation_2_MA to 360 Engage Direct.pptxFPET_Implementation_2_MA to 360 Engage Direct.pptx
FPET_Implementation_2_MA to 360 Engage Direct.pptx
ssuser4ef83d
 
VKS-Python-FIe Handling text CSV Binary.pptx
VKS-Python-FIe Handling text CSV Binary.pptxVKS-Python-FIe Handling text CSV Binary.pptx
VKS-Python-FIe Handling text CSV Binary.pptx
Vinod Srivastava
 
Developing Security Orchestration, Automation, and Response Applications
Developing Security Orchestration, Automation, and Response ApplicationsDeveloping Security Orchestration, Automation, and Response Applications
Developing Security Orchestration, Automation, and Response Applications
VICTOR MAESTRE RAMIREZ
 
VKS-Python Basics for Beginners and advance.pptx
VKS-Python Basics for Beginners and advance.pptxVKS-Python Basics for Beginners and advance.pptx
VKS-Python Basics for Beginners and advance.pptx
Vinod Srivastava
 
Thingyan is now a global treasure! See how people around the world are search...
Thingyan is now a global treasure! See how people around the world are search...Thingyan is now a global treasure! See how people around the world are search...
Thingyan is now a global treasure! See how people around the world are search...
Pixellion
 
computer organization and assembly language.docx
computer organization and assembly language.docxcomputer organization and assembly language.docx
computer organization and assembly language.docx
alisoftwareengineer1
 
How iCode cybertech Helped Me Recover My Lost Funds
How iCode cybertech Helped Me Recover My Lost FundsHow iCode cybertech Helped Me Recover My Lost Funds
How iCode cybertech Helped Me Recover My Lost Funds
ireneschmid345
 
Ppt. Nikhil.pptxnshwuudgcudisisshvehsjks
Ppt. Nikhil.pptxnshwuudgcudisisshvehsjksPpt. Nikhil.pptxnshwuudgcudisisshvehsjks
Ppt. Nikhil.pptxnshwuudgcudisisshvehsjks
panchariyasahil
 
Template_A3nnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnn
Template_A3nnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnTemplate_A3nnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnn
Template_A3nnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnn
cegiver630
 
Principles of information security Chapter 5.ppt
Principles of information security Chapter 5.pptPrinciples of information security Chapter 5.ppt
Principles of information security Chapter 5.ppt
EstherBaguma
 
Cleaned_Lecture 6666666_Simulation_I.pdf
Cleaned_Lecture 6666666_Simulation_I.pdfCleaned_Lecture 6666666_Simulation_I.pdf
Cleaned_Lecture 6666666_Simulation_I.pdf
alcinialbob1234
 
Geometry maths presentation for begginers
Geometry maths presentation for begginersGeometry maths presentation for begginers
Geometry maths presentation for begginers
zrjacob283
 
Digilocker under workingProcess Flow.pptx
Digilocker  under workingProcess Flow.pptxDigilocker  under workingProcess Flow.pptx
Digilocker under workingProcess Flow.pptx
satnamsadguru491
 
Flip flop presenation-Presented By Mubahir khan.pptx
Flip flop presenation-Presented By Mubahir khan.pptxFlip flop presenation-Presented By Mubahir khan.pptx
Flip flop presenation-Presented By Mubahir khan.pptx
mubashirkhan45461
 
Perencanaan Pengendalian-Proyek-Konstruksi-MS-PROJECT.pptx
Perencanaan Pengendalian-Proyek-Konstruksi-MS-PROJECT.pptxPerencanaan Pengendalian-Proyek-Konstruksi-MS-PROJECT.pptx
Perencanaan Pengendalian-Proyek-Konstruksi-MS-PROJECT.pptx
PareaRusan
 
Medical Dataset including visualizations
Medical Dataset including visualizationsMedical Dataset including visualizations
Medical Dataset including visualizations
vishrut8750588758
 
Defense Against LLM Scheming 2025_04_28.pptx
Defense Against LLM Scheming 2025_04_28.pptxDefense Against LLM Scheming 2025_04_28.pptx
Defense Against LLM Scheming 2025_04_28.pptx
Greg Makowski
 
Data Analytics Overview and its applications
Data Analytics Overview and its applicationsData Analytics Overview and its applications
Data Analytics Overview and its applications
JanmejayaMishra7
 
Safety Innovation in Mt. Vernon A Westchester County Model for New Rochelle a...
Safety Innovation in Mt. Vernon A Westchester County Model for New Rochelle a...Safety Innovation in Mt. Vernon A Westchester County Model for New Rochelle a...
Safety Innovation in Mt. Vernon A Westchester County Model for New Rochelle a...
James Francis Paradigm Asset Management
 
FPET_Implementation_2_MA to 360 Engage Direct.pptx
FPET_Implementation_2_MA to 360 Engage Direct.pptxFPET_Implementation_2_MA to 360 Engage Direct.pptx
FPET_Implementation_2_MA to 360 Engage Direct.pptx
ssuser4ef83d
 
VKS-Python-FIe Handling text CSV Binary.pptx
VKS-Python-FIe Handling text CSV Binary.pptxVKS-Python-FIe Handling text CSV Binary.pptx
VKS-Python-FIe Handling text CSV Binary.pptx
Vinod Srivastava
 
Developing Security Orchestration, Automation, and Response Applications
Developing Security Orchestration, Automation, and Response ApplicationsDeveloping Security Orchestration, Automation, and Response Applications
Developing Security Orchestration, Automation, and Response Applications
VICTOR MAESTRE RAMIREZ
 
Ad

Git_Git_Lab_1664715263.pdf

  • 1. Introduction to Git and GitLab 15 May. 2019 | P. Weidenkaff | Introduction to Git and GitLab 0 Pictures from www.atlassian.com/git/tutorials Slides at https://indico.him.uni-mainz.de/event/37/
  • 2. What is a Version Control System (VCS)? • Track changes among (any type of) files • Long term history of changes • Collaborate on files (e.g. source code) • Answer: Who ? Why ? When ? 15 May. 2019 | P. Weidenkaff | Introduction to Git and GitLab 1 Advantages of Git • Distributed VCS • Every user keeps the full set of changes • Independent of network connection or central server • Easy collaboration on code via pull/merge requests • Forking of projects • Became very popular is combination with web interfaces GitLab, GitHub, Bitbucket Pictures from www.atlassian.com/git/tutorials Slides at https://indico.him.uni-mainz.de/event/37/
  • 3. Getting started - git init/add/commit • Getting help man git man git-<subcommand>, e.g. man git-add • Initialize a new repository git init • Create file or add existing ones git add testfile git add *.cxx • First commit git commit –a –m “Initial commit” git commit --amend • Further changes – show differences git status git diff • Exclude files using .gitignore 15 May. 2019 | P. Weidenkaff | Introduction to Git and GitLab 2
  • 4. Inspecting a repository - git log/diff/blame • Inspect commit history git log git log --oneline • Write proper log messages! • Show changes since some commit git diff HEAD~3 git diff f44596f git diff f44596f827263d90cb52fe10c3104bd8cce742bc git diff HEAD~3 -- README.rst • Show who’s responsible for a certain line of code git blame README.rst (Use the IDE of your choice) 15 May. 2019 | P. Weidenkaff | Introduction to Git and GitLab 3
  • 5. Fix mistakes - git checkout/reset/revert • Fix your mistakes – copy file from previous commit git checkout HEAD -- README.rst • Reset all changes to HEAD git reset --hard HEAD • Revert the changes of a single commit git revert HEAD~3 15 May. 2019 | P. Weidenkaff | Introduction to Git and GitLab 4
  • 6. Branches - git branch/clone • List branches git branch (-a) • Create a new branch git branch new git checkout new • Clone remote repository git clone https://git.... git clone git@git.... git clone /local/path/to/repo • Merge branches (new into master) git checkout new git merge master • Remote repositories git remote –v git remote add/remove 15 May. 2019 | P. Weidenkaff | Introduction to Git and GitLab 5 git checkout -b new
  • 7. Exercise I I. Create a repository, add files, commit II. Get repository [email protected]: git-introduction/example-multibranch.git OR: https://gitlab.rlp.net/ git-introduction/example-multibranch.git 1. Show all (remote) branches 2. Pull remote branch new: git checkout origin/new 3. Merge branch new into master 4. Open the conflicting file and solve the merge conflict 5. Commit and push your changes 6. Check the history using git log --oneline --graph --decorate (or use some graphical tool like gitk) 15 May. 2019 | P. Weidenkaff | Introduction to Git and GitLab 6
  • 8. Collaborating on git repositories - GitLab • Public services www.gitlab.com www.github.com • University hosted service gitlab.rlp.com • Web interface to many git functions • Access management to the repository • Management of bug reports (Issues) • Code analysis • Provides releases • Wiki pages • Continuous integration (CI) • Backup and long time storage 15 May. 2019 | P. Weidenkaff | Introduction to Git and GitLab 7
  • 9. Exercise II I. Create a repository on gitlab.rlp.net 1. Use an existing project and initialize a git repository 2. Add a new remote to your existing repository git remote add origin [email protected]: git-introduction/example-multibranch.git 3. Push your repository to GitLab II. Fork an existing repository in GitLab https://gitlab.rlp.net/git-introduction/example-multibranch.git 1. Clone the fork 2. Perform a change and push it to your fork 3. Create a merge request (pull request) on GitLab 15 May. 2019 | P. Weidenkaff | Introduction to Git and GitLab 8
  • 10. Advanced topics Submodules Large file support Continuous integration 15 May. 2019 | P. Weidenkaff | Introduction to Git and GitLab 9
  • 11. Submodules – git submodule • Modular organization of my own code • Dependency of (fast) changing code • Avoid another system dependency • Software typically not available on all Unix systems • Add submodule git submodule add [email protected]:... • Clone respository with submodules git clone [URL] git submodule init git submodule update • Update submodules git submodule update --remote 15 May. 2019 | P. Weidenkaff | Introduction to Git and GitLab 10 git clone --recursive [URL]
  • 12. Large file support – git lfs • Size of the repository matters • Each clone copies every version of every files ever existed within the repository • Problem with large files that change frequently • Full histroy is not necessary for e.g. pictures, ROOT files • lfs only downloads versions referenced by current commit • Mark such files as lfs: git lfs install git lfs • Download a repository with lfs git clone [URL] • Downloaded during git checkout (not git clone) 15 May. 2019 | P. Weidenkaff | Introduction to Git and GitLab 11
  • 13. Continuous integration (CI) • Verify each commit • Build code (on several systems) • Run tests • ThirdParty tools on code quality • Configure on GitLab via .gitlab-ci.yml • Images available on https://hub.docker.com/ • Templates are provided on GitLab 15 May. 2019 | P. Weidenkaff | Introduction to Git and GitLab 12 image: gcc build: stage: build before_script: - apt update && apt -y install make script: - g++ helloworld.cpp -o mybinary artifacts: paths: - mybinary test: stage: test script: - ./runmytests.sh
  • 14. Exercise II I. Submodules 1. Clone including submodules https://github.com/ComPWA/ComPWA.git 2. Update submodules II. LFS 1. Use a custom project and add some files to be tracked via lfs 2. Push the repository to GitLab III. CI 1. Create a repository and add a LaTeX document 2. Upload it to gitlab 3. Setup CI to recreate the document every time the repository is updated 15 May. 2019 | P. Weidenkaff | Introduction to Git and GitLab 13
  • 15. Summary Git and GitLab • Git tracks changes in your code (or other files) • GitLab organizes collaboration on Code • Issues • Merge requests • Access control There is more.... • Advanced git commands git rebase/bisect • Filetypes different from pure text Word, TeX, jupyter notebooks • GitLab Docker registry to store images generated by CI 15 May. 2019 | P. Weidenkaff | Introduction to Git and GitLab 14