Git Workflow Alexey Rybalchenko (GSI Darmstadt, FairRoot group) R3BRoot Development Workshop GSI Darmstadt, July 28, 2015 http://git-scm.com/ https://github.com/
Git Workflow
Alexey Rybalchenko(GSI Darmstadt, FairRoot group)
R3BRoot Development WorkshopGSI Darmstadt, July 28, 2015
http://git-scm.com/ https://github.com/
Git: Distributed Version Control
Alexey Rybalchenko | R3BRoot Development Workshop | 28.07.2015 2/28
GitHub: web-based Git repository hosting
Alexey Rybalchenko | R3BRoot Development Workshop | 28.07.2015 3/28
• 10 million users• 25 million projects (https://github.com/explore)• Web-based GUI, desktop client, mobile client• Access control• Wikis• Bug tracking• Private repositories ($)• And more…
Git Workflow
Alexey Rybalchenko | R3BRoot Development Workshop | 28.07.2015 4/28
Git workflow https://github.com/AnarManafov/GitWorkflow/blob/master/GitWorkflow.markdown Anar Manafov(GSI Darmstadt)
• uninterruptible development
• stable and releasable at any time master
• multilevel protection against conflicts
• delegation of conflict resolution to authors
• multilevel possibility to recover from errors/mistakes before changes land into the master
• clean history of the master branch
Workflow matters more than the tool!
Fork
Alexey Rybalchenko | R3BRoot Development Workshop | 28.07.2015 5/28
“main“repository
developerrepository
fork
Fork
Alexey Rybalchenko | R3BRoot Development Workshop | 28.07.2015 6/28
“main“repository
developerrepository
fork
Clone
Alexey Rybalchenko | R3BRoot Development Workshop | 28.07.2015 7/28
“main“repository
developerrepository
$ git clone https://github.com/alexopus/FairRoot.git fairroot
localrepository
clone
$ git status
Clone remote repository to a local location (automatically checks out the master branch)
Check git status
origin
Checkout
Alexey Rybalchenko | R3BRoot Development Workshop | 28.07.2015 8/28
“main“repository
developerrepository
$ git checkout dev
localrepository
Switch to the ‘dev‘ branch
origin
checkout
Branches:master, dev,
featureX,
RC, HotFix
Create a new branch
Alexey Rybalchenko | R3BRoot Development Workshop | 28.07.2015 9/28
“main“repository
developerrepository
$ git checkout –b improve-logger-levels
localrepository
branch, checkout
Create a new branch ‘improve-logger-levels‘ and switch to it
origin
$ git branch improve-logger-levels
$ git checkout improve-logger-levels=
implement every task/feature on a separate branch!
Inspect what you have changed
Alexey Rybalchenko | R3BRoot Development Workshop | 28.07.2015 10/28
“main“repository
developerrepository
$ git diff
localrepository
diff
See all uncommited changes
origin
Commit the changes (to the local repository)
Alexey Rybalchenko | R3BRoot Development Workshop | 28.07.2015 11/28
“main“repository
developerrepository
$ git commit -m “Improve logger level“
localrepository
commit
Stage file for commit
origin
$ git commit –am “…“$ git add fairmq/FairMQLogger.cxx
Commit the changes with a meaningful message
Stage all changed files and commitOR
. . .
Avoid committing large binary files or files that canbe automatically generated by your development environment!
Update your Fork with the new changes
Alexey Rybalchenko | R3BRoot Development Workshop | 28.07.2015 12/28
“main“repository
developerrepository
localrepository
push
Push the new changes to YOUR fork (origin)
origin
$ git push$ git push origin <branch-name>
GitHub network
Alexey Rybalchenko | R3BRoot Development Workshop | 28.07.2015 13/28
“main“repository
developerrepository
localrepository
origin
Remotes
Alexey Rybalchenko | R3BRoot Development Workshop | 28.07.2015 14/28
“main“repository
developerrepository
localrepository
remote add
origin$ git remote add <name> <address>
List remotes (verbose)
$ git remote -v
Add new remote repository under a <name> of your choice
fairroot <address>
Fetching code from remote repositories
Alexey Rybalchenko | R3BRoot Development Workshop | 28.07.2015 15/28
“main“repository
developerrepository
localrepository
origin
$ git fetch fairroot
Download (or update) the “fairroot“ remote
fairrootfetch
Update your branch with the latest changes
Alexey Rybalchenko | R3BRoot Development Workshop | 28.07.2015 16/28
“main“repository
developerrepository
localrepository
rebase
origin
$ git rebase fairroot/dev
Rebase your current branch to the ‘dev‘ branch of the ‘fairroot‘ remote
fairroot
Potential merge conflicts have to be resolved during this step.Rebasing often will reduce/avoid conflicts!!
Rebasing often will reduce/avoid conflicts!!
Cleanup your work
Alexey Rybalchenko | R3BRoot Development Workshop | 28.07.2015 17/28
“main“repository
developerrepository
localrepository
rebase -i
origin
$ git rebase –i fairroot/dev
Run an interactive rebase
fairroot
Here you can squash (merge) commits, rewrite commit messages, etc.
Update your fork with the cleaned & rebased version
Alexey Rybalchenko | R3BRoot Development Workshop | 28.07.2015 18/28
“main“repository
developerrepository
localrepository
push
origin
$ git push -f
Push your updated
fairroot
Update your fork with the cleaned & rebased version
Alexey Rybalchenko | R3BRoot Development Workshop | 28.07.2015 19/28
“main“repository
developerrepository
localrepository
originfairroot
Open a Pull Request for your code (1/2)
Alexey Rybalchenko | R3BRoot Development Workshop | 28.07.2015 20/28
“main“repository
developerrepository
localrepository
originfairroot
Open a Pull Request for your code (2/2)
Alexey Rybalchenko | R3BRoot Development Workshop | 28.07.2015 21/28
“main“repository
developerrepository
localrepository
originfairroot
pull request
Main repository manager may merge your work
Alexey Rybalchenko | R3BRoot Development Workshop | 28.07.2015 22/28
“main“repository
developerrepository
localrepository
originfairroot
If the Pull Request is conflict-free and all requirements are fulfilled, the manager of the main repository can merge your code in the dev branch.
merge
For further development, rebase your dev branch and create the next feature branch out of it.
Otherwise, the Pull Request will be rejected.
Further details on main repository management:
Git workflow https://github.com/AnarManafov/GitWorkflow/blob/master/GitWorkflow.markdown
Summary
Alexey Rybalchenko | R3BRoot Development Workshop | 28.07.2015 23/28
• fork (GitHub)
• clone (git on local machine(s))
• branch, checkout (git)
• write code (you)
• commit (git)
• rebase (git)
• push (to your own repo on GitHub)
• Pull Request (GitHub)
General Guidelines
Alexey Rybalchenko | R3BRoot Development Workshop | 28.07.2015 24/28
• Contained development: implement every task/feature on a separate branch.
• Only release managers are allowed to work on the central master branch.
• Avoid cherry picking by any means. A good use of branches should prevent the need of "git cherry-pick".
• Avoid creating very large repositories.
• Avoid committing large binary files.
• Do not commit any file, which can be recreated or which is generated automatically by your dev. environment.
Detailed Git workflow
Alexey Rybalchenko | R3BRoot Development Workshop | 28.07.2015 25/28
Git workflow github.com/AnarManafov/GitWorkflow/blob/master/GitWorkflow.markdown
• Tips and HOWTOs• User Stories (examples)• Branches• Git environment setup• Etc…
Many Thanks to: Anar Manafov
Free Git Book
Alexey Rybalchenko | R3BRoot Development Workshop | 28.07.2015 26/28
Git Book http://git-scm.com/book/en/v2
Chapter 2.1: Git Basics
Basic Git Concepts Visualization
Alexey Rybalchenko | R3BRoot Development Workshop | 28.07.2015 27/28
Git visualization http://www.wei-wang.com/ExplainGitWithD3/
Thank You!Git workflow github.com/AnarManafov/GitWorkflow/blob/master/GitWorkflow.markdown
Git visualization http://www.wei-wang.com/ExplainGitWithD3/
Git Book http://git-scm.com/book/en/v2
Alexey Rybalchenko | R3BRoot Development Workshop | 28.07.2015 28/28
Google http://www.google.com