git workflow - gsi · git workflow alexey rybalchenko (gsi darmstadt, fairroot group) r3broot...

28
Git Workflow Alexey Rybalchenko (GSI Darmstadt, FairRoot group) R3BRoot Development Workshop GSI Darmstadt, July 28, 2015 http://git-scm.com/ https://github.com/

Upload: others

Post on 11-Aug-2020

32 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Git Workflow - GSI · Git Workflow Alexey Rybalchenko (GSI Darmstadt, FairRoot group) R3BRoot Development Workshop GSI Darmstadt, July 28, 2015 ... Potential merge conflicts have

Git Workflow

Alexey Rybalchenko(GSI Darmstadt, FairRoot group)

R3BRoot Development WorkshopGSI Darmstadt, July 28, 2015

http://git-scm.com/ https://github.com/

Page 2: Git Workflow - GSI · Git Workflow Alexey Rybalchenko (GSI Darmstadt, FairRoot group) R3BRoot Development Workshop GSI Darmstadt, July 28, 2015 ... Potential merge conflicts have

Git: Distributed Version Control

Alexey Rybalchenko | R3BRoot Development Workshop | 28.07.2015 2/28

Page 3: Git Workflow - GSI · Git Workflow Alexey Rybalchenko (GSI Darmstadt, FairRoot group) R3BRoot Development Workshop GSI Darmstadt, July 28, 2015 ... Potential merge conflicts have

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…

Page 4: Git Workflow - GSI · Git Workflow Alexey Rybalchenko (GSI Darmstadt, FairRoot group) R3BRoot Development Workshop GSI Darmstadt, July 28, 2015 ... Potential merge conflicts have

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!

Page 5: Git Workflow - GSI · Git Workflow Alexey Rybalchenko (GSI Darmstadt, FairRoot group) R3BRoot Development Workshop GSI Darmstadt, July 28, 2015 ... Potential merge conflicts have

Fork

Alexey Rybalchenko | R3BRoot Development Workshop | 28.07.2015 5/28

“main“repository

developerrepository

fork

Page 6: Git Workflow - GSI · Git Workflow Alexey Rybalchenko (GSI Darmstadt, FairRoot group) R3BRoot Development Workshop GSI Darmstadt, July 28, 2015 ... Potential merge conflicts have

Fork

Alexey Rybalchenko | R3BRoot Development Workshop | 28.07.2015 6/28

“main“repository

developerrepository

fork

Page 7: Git Workflow - GSI · Git Workflow Alexey Rybalchenko (GSI Darmstadt, FairRoot group) R3BRoot Development Workshop GSI Darmstadt, July 28, 2015 ... Potential merge conflicts have

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

Page 8: Git Workflow - GSI · Git Workflow Alexey Rybalchenko (GSI Darmstadt, FairRoot group) R3BRoot Development Workshop GSI Darmstadt, July 28, 2015 ... Potential merge conflicts have

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

Page 9: Git Workflow - GSI · Git Workflow Alexey Rybalchenko (GSI Darmstadt, FairRoot group) R3BRoot Development Workshop GSI Darmstadt, July 28, 2015 ... Potential merge conflicts have

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!

Page 10: Git Workflow - GSI · Git Workflow Alexey Rybalchenko (GSI Darmstadt, FairRoot group) R3BRoot Development Workshop GSI Darmstadt, July 28, 2015 ... Potential merge conflicts have

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

Page 11: Git Workflow - GSI · Git Workflow Alexey Rybalchenko (GSI Darmstadt, FairRoot group) R3BRoot Development Workshop GSI Darmstadt, July 28, 2015 ... Potential merge conflicts have

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!

Page 12: Git Workflow - GSI · Git Workflow Alexey Rybalchenko (GSI Darmstadt, FairRoot group) R3BRoot Development Workshop GSI Darmstadt, July 28, 2015 ... Potential merge conflicts have

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>

Page 13: Git Workflow - GSI · Git Workflow Alexey Rybalchenko (GSI Darmstadt, FairRoot group) R3BRoot Development Workshop GSI Darmstadt, July 28, 2015 ... Potential merge conflicts have

GitHub network

Alexey Rybalchenko | R3BRoot Development Workshop | 28.07.2015 13/28

“main“repository

developerrepository

localrepository

origin

Page 14: Git Workflow - GSI · Git Workflow Alexey Rybalchenko (GSI Darmstadt, FairRoot group) R3BRoot Development Workshop GSI Darmstadt, July 28, 2015 ... Potential merge conflicts have

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>

Page 15: Git Workflow - GSI · Git Workflow Alexey Rybalchenko (GSI Darmstadt, FairRoot group) R3BRoot Development Workshop GSI Darmstadt, July 28, 2015 ... Potential merge conflicts have

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

Page 16: Git Workflow - GSI · Git Workflow Alexey Rybalchenko (GSI Darmstadt, FairRoot group) R3BRoot Development Workshop GSI Darmstadt, July 28, 2015 ... Potential merge conflicts have

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!!

Page 17: Git Workflow - GSI · Git Workflow Alexey Rybalchenko (GSI Darmstadt, FairRoot group) R3BRoot Development Workshop GSI Darmstadt, July 28, 2015 ... Potential merge conflicts have

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.

Page 18: Git Workflow - GSI · Git Workflow Alexey Rybalchenko (GSI Darmstadt, FairRoot group) R3BRoot Development Workshop GSI Darmstadt, July 28, 2015 ... Potential merge conflicts have

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

Page 19: Git Workflow - GSI · Git Workflow Alexey Rybalchenko (GSI Darmstadt, FairRoot group) R3BRoot Development Workshop GSI Darmstadt, July 28, 2015 ... Potential merge conflicts have

Update your fork with the cleaned & rebased version

Alexey Rybalchenko | R3BRoot Development Workshop | 28.07.2015 19/28

“main“repository

developerrepository

localrepository

originfairroot

Page 20: Git Workflow - GSI · Git Workflow Alexey Rybalchenko (GSI Darmstadt, FairRoot group) R3BRoot Development Workshop GSI Darmstadt, July 28, 2015 ... Potential merge conflicts have

Open a Pull Request for your code (1/2)

Alexey Rybalchenko | R3BRoot Development Workshop | 28.07.2015 20/28

“main“repository

developerrepository

localrepository

originfairroot

Page 21: Git Workflow - GSI · Git Workflow Alexey Rybalchenko (GSI Darmstadt, FairRoot group) R3BRoot Development Workshop GSI Darmstadt, July 28, 2015 ... Potential merge conflicts have

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

Page 22: Git Workflow - GSI · Git Workflow Alexey Rybalchenko (GSI Darmstadt, FairRoot group) R3BRoot Development Workshop GSI Darmstadt, July 28, 2015 ... Potential merge conflicts have

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

Page 23: Git Workflow - GSI · Git Workflow Alexey Rybalchenko (GSI Darmstadt, FairRoot group) R3BRoot Development Workshop GSI Darmstadt, July 28, 2015 ... Potential merge conflicts have

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)

Page 24: Git Workflow - GSI · Git Workflow Alexey Rybalchenko (GSI Darmstadt, FairRoot group) R3BRoot Development Workshop GSI Darmstadt, July 28, 2015 ... Potential merge conflicts have

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.

Page 25: Git Workflow - GSI · Git Workflow Alexey Rybalchenko (GSI Darmstadt, FairRoot group) R3BRoot Development Workshop GSI Darmstadt, July 28, 2015 ... Potential merge conflicts have

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

Page 26: Git Workflow - GSI · Git Workflow Alexey Rybalchenko (GSI Darmstadt, FairRoot group) R3BRoot Development Workshop GSI Darmstadt, July 28, 2015 ... Potential merge conflicts have

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

Page 27: Git Workflow - GSI · Git Workflow Alexey Rybalchenko (GSI Darmstadt, FairRoot group) R3BRoot Development Workshop GSI Darmstadt, July 28, 2015 ... Potential merge conflicts have

Basic Git Concepts Visualization

Alexey Rybalchenko | R3BRoot Development Workshop | 28.07.2015 27/28

Git visualization http://www.wei-wang.com/ExplainGitWithD3/

Page 28: Git Workflow - GSI · Git Workflow Alexey Rybalchenko (GSI Darmstadt, FairRoot group) R3BRoot Development Workshop GSI Darmstadt, July 28, 2015 ... Potential merge conflicts have

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