SlideShare a Scribd company logo
1 of 15
Download to read offline
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

More Related Content

Similar to Git_Git_Lab_1664715263.pdf

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 ControlGiuseppe Masetti
 
Git for uninitiated
Git for uninitiatedGit for uninitiated
Git for uninitiatedJohn 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 GitHubScott Graham
 
Git, GitHub and Open Source
Git, GitHub and Open SourceGit, GitHub and Open Source
Git, GitHub and Open SourceLorna 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 GitHubKim Moir
 
Introduction to Git for Network Engineers
Introduction to Git for Network EngineersIntroduction to Git for Network Engineers
Introduction to Git for Network EngineersJoel W. King
 
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.pptxAbdul Salam
 
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 configurationKishor Kumar
 
Using Git to Organize Your Project
Using Git to Organize Your ProjectUsing Git to Organize Your Project
Using Git to Organize Your ProjectManish Suwal 'Enwil'
 
Spring Projects Infrastructure
Spring Projects InfrastructureSpring Projects Infrastructure
Spring Projects InfrastructureGunnar Hillert
 

Similar to Git_Git_Lab_1664715263.pdf (20)

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
 
Git hub visualstudiocode
Git hub visualstudiocodeGit hub visualstudiocode
Git hub visualstudiocode
 
Git for uninitiated
Git for uninitiatedGit for uninitiated
Git for uninitiated
 
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
 
Introduction to git
Introduction to gitIntroduction to git
Introduction to git
 
Git, GitHub and Open Source
Git, GitHub and Open SourceGit, GitHub and Open Source
Git, GitHub and Open Source
 
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
 
GitHub Event.pptx
GitHub Event.pptxGitHub Event.pptx
GitHub Event.pptx
 
GIT-FirstPart.ppt
GIT-FirstPart.pptGIT-FirstPart.ppt
GIT-FirstPart.ppt
 
Introduction to Git for Network Engineers
Introduction to Git for Network EngineersIntroduction to Git for Network Engineers
Introduction to Git for Network Engineers
 
Git workshop
Git workshopGit workshop
Git workshop
 
3 Git
3 Git3 Git
3 Git
 
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
 
Git tutorial
Git tutorialGit tutorial
Git tutorial
 
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 .
 
Git installation and configuration
Git installation and configurationGit installation and configuration
Git installation and configuration
 
Using Git to Organize Your Project
Using Git to Organize Your ProjectUsing Git to Organize Your Project
Using Git to Organize Your Project
 
Git & Github
Git & GithubGit & Github
Git & Github
 
Git overview
Git overviewGit overview
Git overview
 
Spring Projects Infrastructure
Spring Projects InfrastructureSpring Projects Infrastructure
Spring Projects Infrastructure
 

Recently uploaded

High Profile Call Girls Service in Jalore { 9332606886 } VVIP NISHA Call Girl...
High Profile Call Girls Service in Jalore { 9332606886 } VVIP NISHA Call Girl...High Profile Call Girls Service in Jalore { 9332606886 } VVIP NISHA Call Girl...
High Profile Call Girls Service in Jalore { 9332606886 } VVIP NISHA Call Girl...kumargunjan9515
 
Top profile Call Girls In Indore [ 7014168258 ] Call Me For Genuine Models We...
Top profile Call Girls In Indore [ 7014168258 ] Call Me For Genuine Models We...Top profile Call Girls In Indore [ 7014168258 ] Call Me For Genuine Models We...
Top profile Call Girls In Indore [ 7014168258 ] Call Me For Genuine Models We...gajnagarg
 
Aspirational Block Program Block Syaldey District - Almora
Aspirational Block Program Block Syaldey District - AlmoraAspirational Block Program Block Syaldey District - Almora
Aspirational Block Program Block Syaldey District - AlmoraGovindSinghDasila
 
Top profile Call Girls In Rohtak [ 7014168258 ] Call Me For Genuine Models We...
Top profile Call Girls In Rohtak [ 7014168258 ] Call Me For Genuine Models We...Top profile Call Girls In Rohtak [ 7014168258 ] Call Me For Genuine Models We...
Top profile Call Girls In Rohtak [ 7014168258 ] Call Me For Genuine Models We...nirzagarg
 
Digital Transformation Playbook by Graham Ware
Digital Transformation Playbook by Graham WareDigital Transformation Playbook by Graham Ware
Digital Transformation Playbook by Graham WareGraham Ware
 
Jual obat aborsi Bandung ( 085657271886 ) Cytote pil telat bulan penggugur ka...
Jual obat aborsi Bandung ( 085657271886 ) Cytote pil telat bulan penggugur ka...Jual obat aborsi Bandung ( 085657271886 ) Cytote pil telat bulan penggugur ka...
Jual obat aborsi Bandung ( 085657271886 ) Cytote pil telat bulan penggugur ka...Klinik kandungan
 
Ranking and Scoring Exercises for Research
Ranking and Scoring Exercises for ResearchRanking and Scoring Exercises for Research
Ranking and Scoring Exercises for ResearchRajesh Mondal
 
Gomti Nagar & best call girls in Lucknow | 9548273370 Independent Escorts & D...
Gomti Nagar & best call girls in Lucknow | 9548273370 Independent Escorts & D...Gomti Nagar & best call girls in Lucknow | 9548273370 Independent Escorts & D...
Gomti Nagar & best call girls in Lucknow | 9548273370 Independent Escorts & D...HyderabadDolls
 
Charbagh + Female Escorts Service in Lucknow | Starting ₹,5K To @25k with A/C...
Charbagh + Female Escorts Service in Lucknow | Starting ₹,5K To @25k with A/C...Charbagh + Female Escorts Service in Lucknow | Starting ₹,5K To @25k with A/C...
Charbagh + Female Escorts Service in Lucknow | Starting ₹,5K To @25k with A/C...HyderabadDolls
 
Top Call Girls in Balaghat 9332606886Call Girls Advance Cash On Delivery Ser...
Top Call Girls in Balaghat  9332606886Call Girls Advance Cash On Delivery Ser...Top Call Girls in Balaghat  9332606886Call Girls Advance Cash On Delivery Ser...
Top Call Girls in Balaghat 9332606886Call Girls Advance Cash On Delivery Ser...kumargunjan9515
 
怎样办理圣地亚哥州立大学毕业证(SDSU毕业证书)成绩单学校原版复制
怎样办理圣地亚哥州立大学毕业证(SDSU毕业证书)成绩单学校原版复制怎样办理圣地亚哥州立大学毕业证(SDSU毕业证书)成绩单学校原版复制
怎样办理圣地亚哥州立大学毕业证(SDSU毕业证书)成绩单学校原版复制vexqp
 
RESEARCH-FINAL-DEFENSE-PPT-TEMPLATE.pptx
RESEARCH-FINAL-DEFENSE-PPT-TEMPLATE.pptxRESEARCH-FINAL-DEFENSE-PPT-TEMPLATE.pptx
RESEARCH-FINAL-DEFENSE-PPT-TEMPLATE.pptxronsairoathenadugay
 
Dubai Call Girls Peeing O525547819 Call Girls Dubai
Dubai Call Girls Peeing O525547819 Call Girls DubaiDubai Call Girls Peeing O525547819 Call Girls Dubai
Dubai Call Girls Peeing O525547819 Call Girls Dubaikojalkojal131
 
SAC 25 Final National, Regional & Local Angel Group Investing Insights 2024 0...
SAC 25 Final National, Regional & Local Angel Group Investing Insights 2024 0...SAC 25 Final National, Regional & Local Angel Group Investing Insights 2024 0...
SAC 25 Final National, Regional & Local Angel Group Investing Insights 2024 0...Elaine Werffeli
 
5CL-ADBA,5cladba, Chinese supplier, safety is guaranteed
5CL-ADBA,5cladba, Chinese supplier, safety is guaranteed5CL-ADBA,5cladba, Chinese supplier, safety is guaranteed
5CL-ADBA,5cladba, Chinese supplier, safety is guaranteedamy56318795
 
Statistics notes ,it includes mean to index numbers
Statistics notes ,it includes mean to index numbersStatistics notes ,it includes mean to index numbers
Statistics notes ,it includes mean to index numberssuginr1
 
Top profile Call Girls In Chandrapur [ 7014168258 ] Call Me For Genuine Model...
Top profile Call Girls In Chandrapur [ 7014168258 ] Call Me For Genuine Model...Top profile Call Girls In Chandrapur [ 7014168258 ] Call Me For Genuine Model...
Top profile Call Girls In Chandrapur [ 7014168258 ] Call Me For Genuine Model...gajnagarg
 
Introduction to Statistics Presentation.pptx
Introduction to Statistics Presentation.pptxIntroduction to Statistics Presentation.pptx
Introduction to Statistics Presentation.pptxAniqa Zai
 
Top profile Call Girls In Bihar Sharif [ 7014168258 ] Call Me For Genuine Mod...
Top profile Call Girls In Bihar Sharif [ 7014168258 ] Call Me For Genuine Mod...Top profile Call Girls In Bihar Sharif [ 7014168258 ] Call Me For Genuine Mod...
Top profile Call Girls In Bihar Sharif [ 7014168258 ] Call Me For Genuine Mod...nirzagarg
 
Nirala Nagar / Cheap Call Girls In Lucknow Phone No 9548273370 Elite Escort S...
Nirala Nagar / Cheap Call Girls In Lucknow Phone No 9548273370 Elite Escort S...Nirala Nagar / Cheap Call Girls In Lucknow Phone No 9548273370 Elite Escort S...
Nirala Nagar / Cheap Call Girls In Lucknow Phone No 9548273370 Elite Escort S...HyderabadDolls
 

Recently uploaded (20)

High Profile Call Girls Service in Jalore { 9332606886 } VVIP NISHA Call Girl...
High Profile Call Girls Service in Jalore { 9332606886 } VVIP NISHA Call Girl...High Profile Call Girls Service in Jalore { 9332606886 } VVIP NISHA Call Girl...
High Profile Call Girls Service in Jalore { 9332606886 } VVIP NISHA Call Girl...
 
Top profile Call Girls In Indore [ 7014168258 ] Call Me For Genuine Models We...
Top profile Call Girls In Indore [ 7014168258 ] Call Me For Genuine Models We...Top profile Call Girls In Indore [ 7014168258 ] Call Me For Genuine Models We...
Top profile Call Girls In Indore [ 7014168258 ] Call Me For Genuine Models We...
 
Aspirational Block Program Block Syaldey District - Almora
Aspirational Block Program Block Syaldey District - AlmoraAspirational Block Program Block Syaldey District - Almora
Aspirational Block Program Block Syaldey District - Almora
 
Top profile Call Girls In Rohtak [ 7014168258 ] Call Me For Genuine Models We...
Top profile Call Girls In Rohtak [ 7014168258 ] Call Me For Genuine Models We...Top profile Call Girls In Rohtak [ 7014168258 ] Call Me For Genuine Models We...
Top profile Call Girls In Rohtak [ 7014168258 ] Call Me For Genuine Models We...
 
Digital Transformation Playbook by Graham Ware
Digital Transformation Playbook by Graham WareDigital Transformation Playbook by Graham Ware
Digital Transformation Playbook by Graham Ware
 
Jual obat aborsi Bandung ( 085657271886 ) Cytote pil telat bulan penggugur ka...
Jual obat aborsi Bandung ( 085657271886 ) Cytote pil telat bulan penggugur ka...Jual obat aborsi Bandung ( 085657271886 ) Cytote pil telat bulan penggugur ka...
Jual obat aborsi Bandung ( 085657271886 ) Cytote pil telat bulan penggugur ka...
 
Ranking and Scoring Exercises for Research
Ranking and Scoring Exercises for ResearchRanking and Scoring Exercises for Research
Ranking and Scoring Exercises for Research
 
Gomti Nagar & best call girls in Lucknow | 9548273370 Independent Escorts & D...
Gomti Nagar & best call girls in Lucknow | 9548273370 Independent Escorts & D...Gomti Nagar & best call girls in Lucknow | 9548273370 Independent Escorts & D...
Gomti Nagar & best call girls in Lucknow | 9548273370 Independent Escorts & D...
 
Charbagh + Female Escorts Service in Lucknow | Starting ₹,5K To @25k with A/C...
Charbagh + Female Escorts Service in Lucknow | Starting ₹,5K To @25k with A/C...Charbagh + Female Escorts Service in Lucknow | Starting ₹,5K To @25k with A/C...
Charbagh + Female Escorts Service in Lucknow | Starting ₹,5K To @25k with A/C...
 
Top Call Girls in Balaghat 9332606886Call Girls Advance Cash On Delivery Ser...
Top Call Girls in Balaghat  9332606886Call Girls Advance Cash On Delivery Ser...Top Call Girls in Balaghat  9332606886Call Girls Advance Cash On Delivery Ser...
Top Call Girls in Balaghat 9332606886Call Girls Advance Cash On Delivery Ser...
 
怎样办理圣地亚哥州立大学毕业证(SDSU毕业证书)成绩单学校原版复制
怎样办理圣地亚哥州立大学毕业证(SDSU毕业证书)成绩单学校原版复制怎样办理圣地亚哥州立大学毕业证(SDSU毕业证书)成绩单学校原版复制
怎样办理圣地亚哥州立大学毕业证(SDSU毕业证书)成绩单学校原版复制
 
RESEARCH-FINAL-DEFENSE-PPT-TEMPLATE.pptx
RESEARCH-FINAL-DEFENSE-PPT-TEMPLATE.pptxRESEARCH-FINAL-DEFENSE-PPT-TEMPLATE.pptx
RESEARCH-FINAL-DEFENSE-PPT-TEMPLATE.pptx
 
Dubai Call Girls Peeing O525547819 Call Girls Dubai
Dubai Call Girls Peeing O525547819 Call Girls DubaiDubai Call Girls Peeing O525547819 Call Girls Dubai
Dubai Call Girls Peeing O525547819 Call Girls Dubai
 
SAC 25 Final National, Regional & Local Angel Group Investing Insights 2024 0...
SAC 25 Final National, Regional & Local Angel Group Investing Insights 2024 0...SAC 25 Final National, Regional & Local Angel Group Investing Insights 2024 0...
SAC 25 Final National, Regional & Local Angel Group Investing Insights 2024 0...
 
5CL-ADBA,5cladba, Chinese supplier, safety is guaranteed
5CL-ADBA,5cladba, Chinese supplier, safety is guaranteed5CL-ADBA,5cladba, Chinese supplier, safety is guaranteed
5CL-ADBA,5cladba, Chinese supplier, safety is guaranteed
 
Statistics notes ,it includes mean to index numbers
Statistics notes ,it includes mean to index numbersStatistics notes ,it includes mean to index numbers
Statistics notes ,it includes mean to index numbers
 
Top profile Call Girls In Chandrapur [ 7014168258 ] Call Me For Genuine Model...
Top profile Call Girls In Chandrapur [ 7014168258 ] Call Me For Genuine Model...Top profile Call Girls In Chandrapur [ 7014168258 ] Call Me For Genuine Model...
Top profile Call Girls In Chandrapur [ 7014168258 ] Call Me For Genuine Model...
 
Introduction to Statistics Presentation.pptx
Introduction to Statistics Presentation.pptxIntroduction to Statistics Presentation.pptx
Introduction to Statistics Presentation.pptx
 
Top profile Call Girls In Bihar Sharif [ 7014168258 ] Call Me For Genuine Mod...
Top profile Call Girls In Bihar Sharif [ 7014168258 ] Call Me For Genuine Mod...Top profile Call Girls In Bihar Sharif [ 7014168258 ] Call Me For Genuine Mod...
Top profile Call Girls In Bihar Sharif [ 7014168258 ] Call Me For Genuine Mod...
 
Nirala Nagar / Cheap Call Girls In Lucknow Phone No 9548273370 Elite Escort S...
Nirala Nagar / Cheap Call Girls In Lucknow Phone No 9548273370 Elite Escort S...Nirala Nagar / Cheap Call Girls In Lucknow Phone No 9548273370 Elite Escort S...
Nirala Nagar / Cheap Call Girls In Lucknow Phone No 9548273370 Elite Escort S...
 

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 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
  • 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 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
  • 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 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]
  • 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