SlideShare a Scribd company logo
COLLABORATION IN
PROJECTS USING GIT
Ivelin Yanev
23.02.2019
OUTLINE
Motivation
1. 4
Differences between SVN and Git
2. 7
Git setup (on Windows)
3. 11
Tools 11
3.1.
Config 13
3.2.
Git metadata and internal files
4. 16
Git submodules
5. 18
Start work on an issue
6. 20
Local work - commit strategy
7. 22
OUTLINE
Remote work - Review process with iRepo/Stash
8. 28
Before Review 28
8.1.
During Review 32
8.2.
Closing the Review 37
8.3.
Demo
9. 44
OUTLINE
Motivation
1. 4
Differences between SVN and Git
2. 7
Git setup (on Windows)
3. 11
Tools
3.1. 11
Config
3.2. 13
Git metadata and internal files
4. 16
Git submodules
5. 18
Start work on an issue
6. 20
Local work - commit strategy
7. 22
MOTIVATION
• Origin/Remote repository used by all team members and CI
à coordination and collaboration is essential
• Problems in case of ignorance
– Difficult merge conflicts
– Unexpected behavior of merged code
– Unclear history of changes
– Barrier for following progress
– Bad traceability of bugs
– …
WHY SHOULD I CARE ABOUT COLLABORATION IN GIT? (1/2)
MOTIVATION
• Personal advantages
– Proper working with git is state-of-the-art for
• Good/best IT companies
• Open-source communities
– Signalize professionalism and discipline
– GitHub as part of own CV
WHY SHOULD I CARE ABOUT COLLABORATION IN GIT? (2/2)
OUTLINE
Motivation
1. 4
Differences between SVN and Git
2. 7
Git setup (on Windows)
3. 11
Tools
3.1. 11
Config
3.2. 13
Git metadata and internal files
4. 16
Git submodules
5. 18
Start work on an issue
6. 20
Local work - commit strategy
7. 22
GIT VS. SVN
SVN GIT
Centralized VCS (Client/Server) Decentralized VCS (Peer-to-Peer, each clone is the
complete repo)
Each branch a separate repo Repo contains all branches
commit affects remote/server commit modifies local repo
push modifies remote/server
Not suitable for code review Suitable for code review
Hard to rewrite history Easy to rewrite history
Few commands (e.g. in TortoiseSVN) A lot of commands, very powerful
Easy to start with Steeper learning curve
WHAT TO KEEP IN MIND
GIT VS. SVN
POPULARITY OF COMMON VCS
Source: https://www.google.com/trends/explore?q=%2Fm%2F05vqwg,%2Fm%2F012ct9,%2Fm%2F08441_,%2Fm%2F08w6d6,%2Fm%2F09d6g&hl=en-US
GIT VS. SVN
SVN GIT
svn checkout <repo/trunk> git clone <completeRepo.git>
svn update git pull
svn commit git commit + git push
svn:ignore .gitignore file
New folder + svn checkout <repo/branchA> git checkout branchA
BASIC COMMANDS COMPARISON
OUTLINE
Motivation
1. 4
Differences between SVN and Git
2. 7
Git setup (on Windows)
3. 11
Tools
3.1. 11
Config
3.2. 13
Git metadata and internal files
4. 16
Git submodules
5. 18
Start work on an issue
6. 20
Local work - commit strategy
7. 22
TOOLS
• Official git client: https://git-scm.com/
– Install with recommended options
– Windows context menu entry
– Git Bash
• git CLI with auto-completion
• Handy Linux commands
(find, grep, ssh-keygen etc.)
• gitk (history tree visualization)
– Git GUI (optional)
• All other tools/clients optional as well
– Eclipse EGit, Atlassian SourceTree etc.
WHAT/ HOW TO INSTALL AND USE
OUTLINE
Motivation
1. 4
Differences between SVN and Git
2. 7
Git setup (on Windows)
3. 11
Tools
3.1. 11
Config
3.2. 13
Git metadata and internal files
4. 16
Git submodules
5. 18
Start work on an issue
6. 20
Local work - commit strategy
7. 22
CONFIG
• System
– File location: (Linux)/etc/gitconfig, (Win)C:/ProgramData/Git/config
– Command: git config --list –system (Does not work on Windows L)
• Global (for user)
– File location: Z:/.gitconfig
– Command: git config --list --global
• Local (repo)
– File location: <REPO_ROOT>/.git/config
– Command: git config --list --local
• Overall configuration
– Command: git config --list
GIT CONFIGURATION FILES
Priority
CONFIG
• Username and email
– git config --global user.name "John Doe“
– git config --global user.email johndoe@example.com
• Handling of line endings (CRLF vs. LF)
– Set in System config during git client installation
– Recommended option: core.autocrlf=true
• SSH keys
– Location: Z:.ssh
– Connect simply and safely to repositories
(http://irepo/plugins/servlet/ssh/account/keys)
IMPORTANT INITIAL SETTINGS
OUTLINE
Motivation
1. 4
Differences between SVN and Git
2. 7
Git setup (on Windows)
3. 11
Tools
3.1. 11
Config
3.2. 13
Git metadata and internal files
4. 16
Git submodules
5. 18
Start work on an issue
6. 20
Local work - commit strategy
7. 22
GIT METADATA AND INTERNAL FILES
• <REPO_ROOT>/.git
– Metadata for the repository
– Objects store, hooks etc.
– Only edit <REPO_ROOT>/.git/config if needed
• <REPO_ROOT>/.gitignore
– Files that should be ignored by Git (IDE-related files, compiled code etc.)
• <REPO_ROOT>/.gitmodules
– Other Git repos used as submodules (next chapter)
• <REPO_ROOT>/.gitattributes
– Commonly used to setup handling of line endings
OUTLINE
Motivation
1. 4
Differences between SVN and Git
2. 7
Git setup (on Windows)
3. 11
Tools
3.1. 11
Config
3.2. 13
Git metadata and internal files
4. 16
Git submodules
5. 18
Start work on an issue
6. 20
Local work - commit strategy
7. 22
GIT SUBMODULES
• Similar to svn externals
• Another Git repo injected in a subfolder of your own repo
• Fixed state
• Do not work (e.g. commit/push) with the submodule
• Describe what to get and where to place it in your tree:
<REPO_ROOT>/.gitmodules
• Really get the content after cloning a Git repo having a submodule:
– git submodule init
– git submodule update
– git submodule status
OUTLINE
Motivation
1. 4
Differences between SVN and Git
2. 7
Git setup (on Windows)
3. 11
Tools
3.1. 11
Config
3.2. 13
Git metadata and internal files
4. 16
Git submodules
5. 18
Start work on an issue
6. 20
Local work - commit strategy
7. 22
START WORK ON AN ISSUE
• Make sure your repository is up-to-date with remote
1. git fetch –p //clean up branch references
2. git checkout develop //go to the main dev branch
3. git pull //make sure it perfoms fast-forward
• Start a new local branch
//iTrac key as name
1. git branch RGHOGI-XXXX
2. git checkout RGHOGI-XXXX
3. …start your work…
OUTLINE
Motivation
1. 4
Differences between SVN and Git
2. 7
Git setup (on Windows)
3. 11
Tools
3.1. 11
Config
3.2. 13
Git metadata and internal files
4. 16
Git submodules
5. 18
Start work on an issue
6. 20
Local work - commit strategy
7. 22
BEST STRATEGY - SMALL COMMITS
MOTIVATION
• Easy to understand
• Simpler resolution of
merge/rebase conflicts
• Your own review
• Separation of formatting and
content changes
• Small, Distinct Commits Say You Care
BEST STRATEGY - SMALL COMMITS
HOW-TO (1/2)
• Small commits - reason for git to have a staging area (index)
• Useful commands for building the index:
– git add <file> //add new or modified file to index
– git add –p <file> //partially add a modified file
– git add -N <new_file> //partially add a new file
git add –p <new_file> //
– git rm <file> //add deleted file to index
BEST STRATEGY - SMALL COMMITS
HOW-TO (2/2)
• How to commit changes placed in index:
– git commit //don’t be lazy to use option ‘-m’,
//write good commit messages instead
– git commit --amend //add changes from index to last commit
COMMIT MESSAGE
DOCUMENTATION ROLE
ORGANIZE MULTIPLE COMMITS
TELL THE DEVELOPMENT STORY
• Reorder, edit, squash, delete etc. commits to form a meaningful commit history
• Useful commands:
– git rebase –i develop //Review/edit all commits in your
//new branch RGHOGI-XXXX
– git rebase –i HEAD~4 //Review/edit last 4 commits in your
//new branch RGHOGI-XXXX
– git rebase --abort //In case things go wrong
OUTLINE
Remote work - Review process with iRepo/Stash
8. 28
Before Review
8.1. 28
During Review
8.2. 32
Closing the Review
8.3. 37
Demo
9. 44
STEP I: REBASE ON LATEST STATE OF DEVELOP BRANCH
THE MOST IMPORTANT SLIDE IN THIS PRESENTATION
• Key to keeping the history clean and clear
• Do this from time to time while working on your branch:
1. …commit or stash your changes…
2. git checkout develop
3. git pull
4. …have a look at the incoming changes…
5. …think if they are relevant for your work…
6. git checkout RGHOGI-XXXX
7. git rebase develop
8. …resolve possible conflicts…
RESOLVE MERGE CONFLICTS
• Git can not resolve all conflicts automatically
• Brain and context information required
• Developer decides what the last state should be
1. git status
2. …look for ‘both modified’ files…
3. …edit the files accordingly…
4. git add <all repaired files>
5. git rebase --continue
STEP II: CREATE NEW PULL REQUEST
PUSH NEW BRANCH AND OPEN PULL REQUEST
• Local repo
– git push --set-upstream origin RGHOGI-XXXX
• iRepo/Stash
– Open pull request from
RGHOGI-XXXX to develop
– Add reviewers
– Start review
OUTLINE
Remote work - Review process with iRepo/Stash
8. 28
Before Review
8.1. 28
During Review
8.2. 32
Closing the Review
8.3. 37
Demo
9. 44
CODE REVIEW GUIDELINES
REVIEWER PART
• Option I: Comment the complete diff (‘Diff’ tab in iRepo)
– Pro:
• More visibility
• Does not disappear after pull request update
– Contra:
• Bulk change
• Many advantages of small commits lost
• Difficult to understand
CODE REVIEW GUIDELINES
REVIEWER PART
• Option II: Comment separate commits (‘Commits’ tab in iRepo)
– Pro:
• Follow the developer’s logic
• Smaller changes
• Easy to understand in case of small commits
– Contra:
• A bit hidden
• Comments disappear after pull request update
CODE REVIEW GUIDELINES
DEVELOPER PART
• Option I: Add new commits for code review remarks
– Pro:
• Easy-to-follow small changes added to the pull request
• Easy to do for the developer
• Other reviewers see what was already discussed/remarked
– Contra:
• Longer commit history
• Interrupted logic flow
• Redundancy
– Hint: Better commit messages than “Fix review comments” preferred
CODE REVIEW GUIDELINES
DEVELOPER PART
• Option II: Edit/Rewrite existing commits for code review remarks
– Pro:
• Condensed commit history
• Logical steps preserved
• Pull request does not grow continuously
– Contra:
• Initial state of pull request lost
• More difficult for the developer to implement
– Hint: Create new commit, rebase interactive and fixup with the corresponding one
OUTLINE
Remote work - Review process with iRepo/Stash
8. 28
Before Review
8.1. 28
During Review
8.2. 32
Closing the Review
8.3. 37
Demo
9. 44
COMPLETE PULL REQUEST (1/2)
• Rebase your branch on develop one last time if needed
– Push branch to update pull request
• iRepo/Stash
– Complete pull request &
delete the RGHOGI-XXXX branch
• Clean-up: Update local repo
1. git checkout develop
2. git pull
3. git branch –d RGHOGI-XXXX
4. git fetch –p
COMPLETE PULL REQUEST (2/2)
• Master branch
//if desired update master with your changes
1. git checkout master
2. git rebase develop OR
git merge develop
3. git push
OUTLINE
Remote work - Review process with iRepo/Stash
8. 28
Before Review
8.1. 28
During Review
8.2. 32
Closing the Review
8.3. 37
Demo
9. 44
DEMO
HANDS-ON (1/2)
• Use case I:
– Work alone on an issue
– Rewrite your commits, reorder, squash
• Use case II:
– Work on an issue
– Colleagues work in the develop branch
– Rebase your work before merging to develop branch
– No conflicts
DEMO
HANDS-ON (2/2)
• Use case III:
– Work on an issue
– Colleagues work in the develop branch
– Rebase your work before merging to develop branch
– Resolve conflicts
• Use case IV:
– Work with colleagues on the same issue
– Depending branches
EXTRA HINT I: GIT EMERGENCY HELP
IN CASE OF TROUBLE
• Case I: No valuable local changes
– Delete everything
– Clone the repo again
• Case II: Valuable local changes
– git reflog
– git reset --hard <id>
– History of issued git commands
EXTRA HINT II: COPY COMMITS TO ANOTHER BRANCH
E.G. COPY FROM DEVELOP TO RELEASE
1. Checkout target branch
(e.g. release)
2. Note the ID of the top commit M
3. Copy commits with ID
P, Q and R from develop

More Related Content

PPTX
2015-ghci-presentation-git_gerritJenkins_final
PDF
Essential git for developers
PPTX
PPTX
Git 101
PPTX
Gerrit Code Review
PDF
01 git interview questions &amp; answers
PDF
Gerrit Code Review
2015-ghci-presentation-git_gerritJenkins_final
Essential git for developers
Git 101
Gerrit Code Review
01 git interview questions &amp; answers
Gerrit Code Review

What's hot (20)

PDF
How to plan and define your CI-CD pipeline
PPTX
[Public] gerrit concepts and workflows
PDF
Git for uninitiated
PDF
Git Introduction Tutorial
PDF
What the git? - SAP Inside Track Munich 2016
PPTX
Techoalien git
PDF
Software Versioning with Bitbucket and Eclipse
PDF
Code Review with Git and Gerrit - Devoxx 2011 - Tools in Action - 2011-11-14
PDF
Git Tutorial
PDF
The Basics of Open Source Collaboration With Git and GitHub
PDF
Managing e commerce systems codebase with git
PPTX
Using Git and BitBucket
PPTX
Source Code Management for Beginners: Become a Contributor with Git and GitHub
PPTX
Git Pull Requests
KEY
Gerrit Workshop
PDF
Version control and GIT Primer
PPTX
Using Git/Gerrit and Jenkins to Manage the Code Review Processord
PDF
PDF
Git Workflow
PPT
Git Introduction
How to plan and define your CI-CD pipeline
[Public] gerrit concepts and workflows
Git for uninitiated
Git Introduction Tutorial
What the git? - SAP Inside Track Munich 2016
Techoalien git
Software Versioning with Bitbucket and Eclipse
Code Review with Git and Gerrit - Devoxx 2011 - Tools in Action - 2011-11-14
Git Tutorial
The Basics of Open Source Collaboration With Git and GitHub
Managing e commerce systems codebase with git
Using Git and BitBucket
Source Code Management for Beginners: Become a Contributor with Git and GitHub
Git Pull Requests
Gerrit Workshop
Version control and GIT Primer
Using Git/Gerrit and Jenkins to Manage the Code Review Processord
Git Workflow
Git Introduction
Ad

Similar to Git collaboration (20)

PDF
Git training v10
PDF
Git workshop
PPTX
Version control git day02
PPTX
Git and GitHub PowerPoint Presentation**
PPTX
Introduction to Git and Github
PDF
Git 101 Workshop
PDF
You're doing it wrong! Git it right!
PPTX
Lets git to it
ODP
Introduction to Git
PDF
Git - An Introduction
PPTX
Git basic stanley hsiao 2010_12_15
PPTX
Introduction to git and githhub with practicals.pptx
PDF
PPT
Introduction to git
PDF
Introducing Git and git flow
PPTX
github ppt git ppt on git hub to know ab
PPTX
Introduction to GitHub, Open Source and Tech Article
PPTX
GIT.pptx
PDF
Bedjango talk about Git & GitHub
PDF
Git 入门 与 实践
Git training v10
Git workshop
Version control git day02
Git and GitHub PowerPoint Presentation**
Introduction to Git and Github
Git 101 Workshop
You're doing it wrong! Git it right!
Lets git to it
Introduction to Git
Git - An Introduction
Git basic stanley hsiao 2010_12_15
Introduction to git and githhub with practicals.pptx
Introduction to git
Introducing Git and git flow
github ppt git ppt on git hub to know ab
Introduction to GitHub, Open Source and Tech Article
GIT.pptx
Bedjango talk about Git & GitHub
Git 入门 与 实践
Ad

More from Ivelin Yanev (11)

PDF
Quarkus Extensions Turbocharge for Java Microservices.pdf
PDF
Empowering Your Java Applications with Quarkus. A New Era of Fast, Efficient,...
PDF
Project Loom
PPTX
Building flexible ETL pipelines with Apache Camel on Quarkus
PDF
Java exeptions
PDF
Introducing java oop concepts
PDF
Introducing generic types
PDF
Java features. Java 8, 9, 10, 11
PDF
Design principles
PDF
Java 9 modularity+
PDF
Intoduction Internet of Things
Quarkus Extensions Turbocharge for Java Microservices.pdf
Empowering Your Java Applications with Quarkus. A New Era of Fast, Efficient,...
Project Loom
Building flexible ETL pipelines with Apache Camel on Quarkus
Java exeptions
Introducing java oop concepts
Introducing generic types
Java features. Java 8, 9, 10, 11
Design principles
Java 9 modularity+
Intoduction Internet of Things

Recently uploaded (20)

PPTX
Simulation of electric circuit laws using tinkercad.pptx
PPTX
MET 305 MODULE 1 KTU 2019 SCHEME 25.pptx
PDF
Structs to JSON How Go Powers REST APIs.pdf
PPTX
436813905-LNG-Process-Overview-Short.pptx
PPTX
Ship’s Structural Components.pptx 7.7 Mb
PPTX
Lesson 3_Tessellation.pptx finite Mathematics
PPTX
Glazing at Facade, functions, types of glazing
PDF
Monitoring Global Terrestrial Surface Water Height using Remote Sensing - ARS...
PPTX
KTU 2019 -S7-MCN 401 MODULE 2-VINAY.pptx
PDF
Introduction to Data Science: data science process
PDF
algorithms-16-00088-v2hghjjnjnhhhnnjhj.pdf
PDF
classification of cubic lattice structure
PDF
MCAD-Guidelines. Modernization of command Area Development, Guideines
PPTX
AgentX UiPath Community Webinar series - Delhi
PDF
International Journal of Information Technology Convergence and Services (IJI...
PDF
A Framework for Securing Personal Data Shared by Users on the Digital Platforms
PDF
Traditional Exams vs Continuous Assessment in Boarding Schools.pdf
PPTX
Practice Questions on recent development part 1.pptx
PPTX
Soil science - sampling procedures for soil science lab
Simulation of electric circuit laws using tinkercad.pptx
MET 305 MODULE 1 KTU 2019 SCHEME 25.pptx
Structs to JSON How Go Powers REST APIs.pdf
436813905-LNG-Process-Overview-Short.pptx
Ship’s Structural Components.pptx 7.7 Mb
Lesson 3_Tessellation.pptx finite Mathematics
Glazing at Facade, functions, types of glazing
Monitoring Global Terrestrial Surface Water Height using Remote Sensing - ARS...
KTU 2019 -S7-MCN 401 MODULE 2-VINAY.pptx
Introduction to Data Science: data science process
algorithms-16-00088-v2hghjjnjnhhhnnjhj.pdf
classification of cubic lattice structure
MCAD-Guidelines. Modernization of command Area Development, Guideines
AgentX UiPath Community Webinar series - Delhi
International Journal of Information Technology Convergence and Services (IJI...
A Framework for Securing Personal Data Shared by Users on the Digital Platforms
Traditional Exams vs Continuous Assessment in Boarding Schools.pdf
Practice Questions on recent development part 1.pptx
Soil science - sampling procedures for soil science lab

Git collaboration

  • 1. COLLABORATION IN PROJECTS USING GIT Ivelin Yanev 23.02.2019
  • 2. OUTLINE Motivation 1. 4 Differences between SVN and Git 2. 7 Git setup (on Windows) 3. 11 Tools 11 3.1. Config 13 3.2. Git metadata and internal files 4. 16 Git submodules 5. 18 Start work on an issue 6. 20 Local work - commit strategy 7. 22
  • 3. OUTLINE Remote work - Review process with iRepo/Stash 8. 28 Before Review 28 8.1. During Review 32 8.2. Closing the Review 37 8.3. Demo 9. 44
  • 4. OUTLINE Motivation 1. 4 Differences between SVN and Git 2. 7 Git setup (on Windows) 3. 11 Tools 3.1. 11 Config 3.2. 13 Git metadata and internal files 4. 16 Git submodules 5. 18 Start work on an issue 6. 20 Local work - commit strategy 7. 22
  • 5. MOTIVATION • Origin/Remote repository used by all team members and CI à coordination and collaboration is essential • Problems in case of ignorance – Difficult merge conflicts – Unexpected behavior of merged code – Unclear history of changes – Barrier for following progress – Bad traceability of bugs – … WHY SHOULD I CARE ABOUT COLLABORATION IN GIT? (1/2)
  • 6. MOTIVATION • Personal advantages – Proper working with git is state-of-the-art for • Good/best IT companies • Open-source communities – Signalize professionalism and discipline – GitHub as part of own CV WHY SHOULD I CARE ABOUT COLLABORATION IN GIT? (2/2)
  • 7. OUTLINE Motivation 1. 4 Differences between SVN and Git 2. 7 Git setup (on Windows) 3. 11 Tools 3.1. 11 Config 3.2. 13 Git metadata and internal files 4. 16 Git submodules 5. 18 Start work on an issue 6. 20 Local work - commit strategy 7. 22
  • 8. GIT VS. SVN SVN GIT Centralized VCS (Client/Server) Decentralized VCS (Peer-to-Peer, each clone is the complete repo) Each branch a separate repo Repo contains all branches commit affects remote/server commit modifies local repo push modifies remote/server Not suitable for code review Suitable for code review Hard to rewrite history Easy to rewrite history Few commands (e.g. in TortoiseSVN) A lot of commands, very powerful Easy to start with Steeper learning curve WHAT TO KEEP IN MIND
  • 9. GIT VS. SVN POPULARITY OF COMMON VCS Source: https://www.google.com/trends/explore?q=%2Fm%2F05vqwg,%2Fm%2F012ct9,%2Fm%2F08441_,%2Fm%2F08w6d6,%2Fm%2F09d6g&hl=en-US
  • 10. GIT VS. SVN SVN GIT svn checkout <repo/trunk> git clone <completeRepo.git> svn update git pull svn commit git commit + git push svn:ignore .gitignore file New folder + svn checkout <repo/branchA> git checkout branchA BASIC COMMANDS COMPARISON
  • 11. OUTLINE Motivation 1. 4 Differences between SVN and Git 2. 7 Git setup (on Windows) 3. 11 Tools 3.1. 11 Config 3.2. 13 Git metadata and internal files 4. 16 Git submodules 5. 18 Start work on an issue 6. 20 Local work - commit strategy 7. 22
  • 12. TOOLS • Official git client: https://git-scm.com/ – Install with recommended options – Windows context menu entry – Git Bash • git CLI with auto-completion • Handy Linux commands (find, grep, ssh-keygen etc.) • gitk (history tree visualization) – Git GUI (optional) • All other tools/clients optional as well – Eclipse EGit, Atlassian SourceTree etc. WHAT/ HOW TO INSTALL AND USE
  • 13. OUTLINE Motivation 1. 4 Differences between SVN and Git 2. 7 Git setup (on Windows) 3. 11 Tools 3.1. 11 Config 3.2. 13 Git metadata and internal files 4. 16 Git submodules 5. 18 Start work on an issue 6. 20 Local work - commit strategy 7. 22
  • 14. CONFIG • System – File location: (Linux)/etc/gitconfig, (Win)C:/ProgramData/Git/config – Command: git config --list –system (Does not work on Windows L) • Global (for user) – File location: Z:/.gitconfig – Command: git config --list --global • Local (repo) – File location: <REPO_ROOT>/.git/config – Command: git config --list --local • Overall configuration – Command: git config --list GIT CONFIGURATION FILES Priority
  • 15. CONFIG • Username and email – git config --global user.name "John Doe“ – git config --global user.email [email protected] • Handling of line endings (CRLF vs. LF) – Set in System config during git client installation – Recommended option: core.autocrlf=true • SSH keys – Location: Z:.ssh – Connect simply and safely to repositories (http://irepo/plugins/servlet/ssh/account/keys) IMPORTANT INITIAL SETTINGS
  • 16. OUTLINE Motivation 1. 4 Differences between SVN and Git 2. 7 Git setup (on Windows) 3. 11 Tools 3.1. 11 Config 3.2. 13 Git metadata and internal files 4. 16 Git submodules 5. 18 Start work on an issue 6. 20 Local work - commit strategy 7. 22
  • 17. GIT METADATA AND INTERNAL FILES • <REPO_ROOT>/.git – Metadata for the repository – Objects store, hooks etc. – Only edit <REPO_ROOT>/.git/config if needed • <REPO_ROOT>/.gitignore – Files that should be ignored by Git (IDE-related files, compiled code etc.) • <REPO_ROOT>/.gitmodules – Other Git repos used as submodules (next chapter) • <REPO_ROOT>/.gitattributes – Commonly used to setup handling of line endings
  • 18. OUTLINE Motivation 1. 4 Differences between SVN and Git 2. 7 Git setup (on Windows) 3. 11 Tools 3.1. 11 Config 3.2. 13 Git metadata and internal files 4. 16 Git submodules 5. 18 Start work on an issue 6. 20 Local work - commit strategy 7. 22
  • 19. GIT SUBMODULES • Similar to svn externals • Another Git repo injected in a subfolder of your own repo • Fixed state • Do not work (e.g. commit/push) with the submodule • Describe what to get and where to place it in your tree: <REPO_ROOT>/.gitmodules • Really get the content after cloning a Git repo having a submodule: – git submodule init – git submodule update – git submodule status
  • 20. OUTLINE Motivation 1. 4 Differences between SVN and Git 2. 7 Git setup (on Windows) 3. 11 Tools 3.1. 11 Config 3.2. 13 Git metadata and internal files 4. 16 Git submodules 5. 18 Start work on an issue 6. 20 Local work - commit strategy 7. 22
  • 21. START WORK ON AN ISSUE • Make sure your repository is up-to-date with remote 1. git fetch –p //clean up branch references 2. git checkout develop //go to the main dev branch 3. git pull //make sure it perfoms fast-forward • Start a new local branch //iTrac key as name 1. git branch RGHOGI-XXXX 2. git checkout RGHOGI-XXXX 3. …start your work…
  • 22. OUTLINE Motivation 1. 4 Differences between SVN and Git 2. 7 Git setup (on Windows) 3. 11 Tools 3.1. 11 Config 3.2. 13 Git metadata and internal files 4. 16 Git submodules 5. 18 Start work on an issue 6. 20 Local work - commit strategy 7. 22
  • 23. BEST STRATEGY - SMALL COMMITS MOTIVATION • Easy to understand • Simpler resolution of merge/rebase conflicts • Your own review • Separation of formatting and content changes • Small, Distinct Commits Say You Care
  • 24. BEST STRATEGY - SMALL COMMITS HOW-TO (1/2) • Small commits - reason for git to have a staging area (index) • Useful commands for building the index: – git add <file> //add new or modified file to index – git add –p <file> //partially add a modified file – git add -N <new_file> //partially add a new file git add –p <new_file> // – git rm <file> //add deleted file to index
  • 25. BEST STRATEGY - SMALL COMMITS HOW-TO (2/2) • How to commit changes placed in index: – git commit //don’t be lazy to use option ‘-m’, //write good commit messages instead – git commit --amend //add changes from index to last commit
  • 27. ORGANIZE MULTIPLE COMMITS TELL THE DEVELOPMENT STORY • Reorder, edit, squash, delete etc. commits to form a meaningful commit history • Useful commands: – git rebase –i develop //Review/edit all commits in your //new branch RGHOGI-XXXX – git rebase –i HEAD~4 //Review/edit last 4 commits in your //new branch RGHOGI-XXXX – git rebase --abort //In case things go wrong
  • 28. OUTLINE Remote work - Review process with iRepo/Stash 8. 28 Before Review 8.1. 28 During Review 8.2. 32 Closing the Review 8.3. 37 Demo 9. 44
  • 29. STEP I: REBASE ON LATEST STATE OF DEVELOP BRANCH THE MOST IMPORTANT SLIDE IN THIS PRESENTATION • Key to keeping the history clean and clear • Do this from time to time while working on your branch: 1. …commit or stash your changes… 2. git checkout develop 3. git pull 4. …have a look at the incoming changes… 5. …think if they are relevant for your work… 6. git checkout RGHOGI-XXXX 7. git rebase develop 8. …resolve possible conflicts…
  • 30. RESOLVE MERGE CONFLICTS • Git can not resolve all conflicts automatically • Brain and context information required • Developer decides what the last state should be 1. git status 2. …look for ‘both modified’ files… 3. …edit the files accordingly… 4. git add <all repaired files> 5. git rebase --continue
  • 31. STEP II: CREATE NEW PULL REQUEST PUSH NEW BRANCH AND OPEN PULL REQUEST • Local repo – git push --set-upstream origin RGHOGI-XXXX • iRepo/Stash – Open pull request from RGHOGI-XXXX to develop – Add reviewers – Start review
  • 32. OUTLINE Remote work - Review process with iRepo/Stash 8. 28 Before Review 8.1. 28 During Review 8.2. 32 Closing the Review 8.3. 37 Demo 9. 44
  • 33. CODE REVIEW GUIDELINES REVIEWER PART • Option I: Comment the complete diff (‘Diff’ tab in iRepo) – Pro: • More visibility • Does not disappear after pull request update – Contra: • Bulk change • Many advantages of small commits lost • Difficult to understand
  • 34. CODE REVIEW GUIDELINES REVIEWER PART • Option II: Comment separate commits (‘Commits’ tab in iRepo) – Pro: • Follow the developer’s logic • Smaller changes • Easy to understand in case of small commits – Contra: • A bit hidden • Comments disappear after pull request update
  • 35. CODE REVIEW GUIDELINES DEVELOPER PART • Option I: Add new commits for code review remarks – Pro: • Easy-to-follow small changes added to the pull request • Easy to do for the developer • Other reviewers see what was already discussed/remarked – Contra: • Longer commit history • Interrupted logic flow • Redundancy – Hint: Better commit messages than “Fix review comments” preferred
  • 36. CODE REVIEW GUIDELINES DEVELOPER PART • Option II: Edit/Rewrite existing commits for code review remarks – Pro: • Condensed commit history • Logical steps preserved • Pull request does not grow continuously – Contra: • Initial state of pull request lost • More difficult for the developer to implement – Hint: Create new commit, rebase interactive and fixup with the corresponding one
  • 37. OUTLINE Remote work - Review process with iRepo/Stash 8. 28 Before Review 8.1. 28 During Review 8.2. 32 Closing the Review 8.3. 37 Demo 9. 44
  • 38. COMPLETE PULL REQUEST (1/2) • Rebase your branch on develop one last time if needed – Push branch to update pull request • iRepo/Stash – Complete pull request & delete the RGHOGI-XXXX branch • Clean-up: Update local repo 1. git checkout develop 2. git pull 3. git branch –d RGHOGI-XXXX 4. git fetch –p
  • 39. COMPLETE PULL REQUEST (2/2) • Master branch //if desired update master with your changes 1. git checkout master 2. git rebase develop OR git merge develop 3. git push
  • 40. OUTLINE Remote work - Review process with iRepo/Stash 8. 28 Before Review 8.1. 28 During Review 8.2. 32 Closing the Review 8.3. 37 Demo 9. 44
  • 41. DEMO HANDS-ON (1/2) • Use case I: – Work alone on an issue – Rewrite your commits, reorder, squash • Use case II: – Work on an issue – Colleagues work in the develop branch – Rebase your work before merging to develop branch – No conflicts
  • 42. DEMO HANDS-ON (2/2) • Use case III: – Work on an issue – Colleagues work in the develop branch – Rebase your work before merging to develop branch – Resolve conflicts • Use case IV: – Work with colleagues on the same issue – Depending branches
  • 43. EXTRA HINT I: GIT EMERGENCY HELP IN CASE OF TROUBLE • Case I: No valuable local changes – Delete everything – Clone the repo again • Case II: Valuable local changes – git reflog – git reset --hard <id> – History of issued git commands
  • 44. EXTRA HINT II: COPY COMMITS TO ANOTHER BRANCH E.G. COPY FROM DEVELOP TO RELEASE 1. Checkout target branch (e.g. release) 2. Note the ID of the top commit M 3. Copy commits with ID P, Q and R from develop