Git Workflows Sylvain Bouveret, Grgory Mouni, Matthieu Moy 2017 - - PowerPoint PPT Presentation

git workflows
SMART_READER_LITE
LIVE PREVIEW

Git Workflows Sylvain Bouveret, Grgory Mouni, Matthieu Moy 2017 - - PowerPoint PPT Presentation

Git Workflows Sylvain Bouveret, Grgory Mouni, Matthieu Moy 2017 [first].[last]@imag.fr http://recherche.noiraudes.net/resources/git/git-workflow-slides.pdf Git Workflow 1 / 16 Goals of the presentation Global history: multiple


slide-1
SLIDE 1

Git Workflows

Sylvain Bouveret, Grégory Mounié, Matthieu Moy 2017

[first].[last]@imag.fr http://recherche.noiraudes.net/resources/git/git-workflow-slides.pdf

1 / 16 Git Workflow

slide-2
SLIDE 2

Goals of the presentation

  • Global history: multiple workflow
  • Global history: branching, rebasing, stashing

2 / 16 Git Workflow

slide-3
SLIDE 3

Workflows

slide-4
SLIDE 4

Branches

Branching exists in most VCS. The goal is to keep track separately

  • f the various parallel works done on an on-going software

development. This is Git killing feature: Git branch management (and merge) is lightweight and efficient. Thus it is quite easy to split the work among the developpers and still let them work easily together toward the common goal. But it is not a magic bullet: the splitting of the work should be handle with care.

3 / 16 Git Workflow

slide-5
SLIDE 5

Example of bad splitting: per developer branches

Pro

  • simple to define and set-up ✓

Cons

  • missing information: to find something, you need to know

who did it ✗

  • redundant information: committer and branch name are

strongly related ✗

  • confusing and error prone code sharing, blending new feature

development and bug correction ✗

  • developers use old version of common code ✗
  • As it does not enforce convergence of code ⇒ the multiple

incompatible development are increasingly difficult to merge ✗

4 / 16 Git Workflow

slide-6
SLIDE 6

Better splitting: per topic branches

  • master branch contain

release versions

  • develop branch contain
  • ngoing development
  • release branch to prepare

new release in master

  • hotfix branch for bug

correction of release version

  • feature branch to develop

new features

[Vincent Driessen, http://nvie.com/posts/ a-successful-git-branching-model/]

5 / 16 Git Workflow

slide-7
SLIDE 7

Code sharing models

Distributed VCS such as Git are ... distributed. The code is thus modified at several places at the same time. There are many different ways to share the code modifications between repositories.

6 / 16 Git Workflow

slide-8
SLIDE 8

Code sharing: centralized workflow

central repository developer repository developer repository developer repository

Similar to SVN way of life, just fully operational with branches, merge and

  • ff-line work. Quite good

for small teams.

7 / 16 Git Workflow

slide-9
SLIDE 9

Code sharing: centralized workflow

central repository developer repository developer repository developer repository

Similar to SVN way of life, just fully operational with branches, merge and

  • ff-line work. Quite good

for small teams. Additional transfers using git are easy and safe ! The tricky part The most important point is to use git for transfer patches. Any transfer outside git can not be taken into account in futur merge.

7 / 16 Git Workflow

slide-10
SLIDE 10

Centralized workflow

1

❞♦ {

2

✇❤✐❧❡ ( nothing_interesting ())

3

work ();

4

✇❤✐❧❡ ( uncommited_changes ()) {

5

✇❤✐❧❡ (! happy) { // git diff --staged ?

6

✇❤✐❧❡ (! enough) git add -p;

7

✇❤✐❧❡ (too_much) git reset -p;

8

}

9

git commit; // no -a

10

✐❢ ( nothing_interesting ())

11

git stash;

12

}

13

✇❤✐❧❡ (! happy)

14

git rebase -i;

15

} ✇❤✐❧❡ (! done);

16

git push; // send code to central repository

8 / 16 Git Workflow

slide-11
SLIDE 11

Code sharing: Github workflow

blessed repository integration repository developer private repository developer public repository pull

  • Released and official

branches are stored in the blessed repository.

  • Contributors forks and works

privately

  • Contributors publish their

work and ask for merge

  • Integrators merges then

publish the contributions

9 / 16 Git Workflow

slide-12
SLIDE 12

Code sharing: Github workflow

blessed repository integration repository developer private repository developer public repository push

  • Released and official

branches are stored in the blessed repository.

  • Contributors forks and works

privately

  • Contributors publish their

work and ask for merge

  • Integrators merges then

publish the contributions

9 / 16 Git Workflow

slide-13
SLIDE 13

Code sharing: Github workflow

blessed repository integration repository developer private repository developer public repository pull

  • Released and official

branches are stored in the blessed repository.

  • Contributors forks and works

privately

  • Contributors publish their

work and ask for merge

  • Integrators merges then

publish the contributions

9 / 16 Git Workflow

slide-14
SLIDE 14

Code sharing: Github workflow

blessed repository integration repository developer private repository developer public repository push

  • Released and official

branches are stored in the blessed repository.

  • Contributors forks and works

privately

  • Contributors publish their

work and ask for merge

  • Integrators merges then

publish the contributions

9 / 16 Git Workflow

slide-15
SLIDE 15

Code sharing: Github workflow

blessed repository integration repository developer private repository developer public repository pull push pull push

  • Released and official

branches are stored in the blessed repository.

  • Contributors forks and works

privately

  • Contributors publish their

work and ask for merge

  • Integrators merges then

publish the contributions Public mailing list as public repository Git patches can be send by email (git format-patch -1), published in mailing-list (eg. bug-gnu-emacs@gnu.org), then integrated (git am)

9 / 16 Git Workflow

slide-16
SLIDE 16

Triangular Workflow with pull-requests

  • Developers pull from upstream, and push to a “to be merged”

location

  • Someone else reviews the code and merges it upstream

Upstream A’s public repo A’s private repo clone, pull push merge B’s public repo B’s private repo clone, pull push merge

10 / 16 Git Workflow

slide-17
SLIDE 17

Pull-requests in Practice

Contributor create a branch, commit, push Contributor click “Create pull request” (GitHub, GitLab, BitBucket, ...), or git request-pull Maintainer receives an email Maintainer review, comment, ask changes Maintainer merge the pull-request The code review is the major point for code quality insurance !

11 / 16 Git Workflow

slide-18
SLIDE 18

Code Review

  • What we’d like:
  • 1. A writes code, commits, pushes
  • 2. B does a review
  • 3. B merges to upstream
  • What usually happens:
  • 1. A writes code, commits, pushes
  • 2. B does a review
  • 3. B requests some changes
  • 4. ... then ?

12 / 16 Git Workflow

slide-19
SLIDE 19

Iterating Code Reviews

  • At least 2 ways to deal with changes between reviews:
  • 1. Add more commits to the pull request and push them on top
  • 2. Rewrite commits (rebase -i, . . . ) and overwrite the old pull

request

  • The resulting history is clean
  • Much easier for reviewers joining the review effort at iteration

2

  • e.g. On Git’s mailing-list, 10 iterations is not uncommon.

13 / 16 Git Workflow

slide-20
SLIDE 20

Code sharing: Linux kernel workflow

dictator repository public repository lieutenant public repository developer public repository developer public repository

  • Code review and basic

filtering of contributions is done by the lieutenants

  • Final decision is done by the

benevolent dictator

  • Lieutenant repositories are

the testbeds of new ideas that mature in it before upstream submission

14 / 16 Git Workflow

slide-21
SLIDE 21

Code sharing: remote management

Remote allows to work with several sources and sink $ git remote add lieutenant git://.../public.git $ git remote

  • rigin

lieutenant $ git fetch lieutenant ... $ git branch -r

  • rigin/HEAD -> origin/master
  • rigin/master

lieutenant/master $ git checkout -b lieutenant lieutenant/master

15 / 16 Git Workflow

slide-22
SLIDE 22

Branches and tags in practice

slide-23
SLIDE 23

Branches and Tags in Practice

  • Create a local branch and check it out:

git checkout -b branch-name

  • Switch to a branch:

git checkout branch-name

  • List local branches:

git branch

  • List all branches (including remote-tracking):

git branch -a

  • Create a tag:

git tag tag-name

16 / 16 Git Workflow