6. Gitflow Workflow
The Gitflow Workflow is derived from Vincent
Driessen at nvie.
He wrote a post on his blog “A successful Git
branching model”. You can read it on http://nvie.com/
posts/a-successful-git-branching-model/
The Gitflow Workflow defines a strict branching
model designed around the project release.
Gitflow Workflow is a robust framework for managing
larger projects.
7. The main branches
The central repo holds two historical branches
with an infinite lifetime:
• master
• develop
8.
9. master
The master branch at origin should be familiar to
every Git user.
We consider origin/master to be the main branch
where the source code of HEAD always reflects a
production-ready state.
10. develop
Parallel to the master branch, another branch exists called
develop.
We consider origin/develop to be the main branch where the
source code of HEAD always reflects a state with the latest
delivered development changes for the next release. Some
would call this the “integration branch”.
This is where any automatic nightly builds are built from.
When the source code in the develop branch reaches a stable
point and is ready to be released, all of the changes should be
merged back into master somehow and then tagged with a
release number.
11. Supporting branches
The different types of branches we may use are:
• Feature branches
• Release branches
• Hotfix branches
Each of these branches have a specific purpose and
are bound to strict rules as to which branches may
be their originating branch and which branches must
be their merge targets.
12. Feature branches (1)
May branch off from develop
Must merge back into develop
Branch naming convention: anything except
master, develop, release-*, or hotfix-*
13. Feature branches (2)
Feature branches are sometimes called topic
branches.
They are used to develop new features for the
upcoming or a distant future release.
Feature branches typically exist in developer
repos only, not in origin.
14. Feature branches (3)
Finished features may be merged into the develop
branch using the --no-ff flag.
This causes the merge to always create a new
commit object, even if the merge could be
performed with a fast-forward.
This avoids losing information about the historical
existence of a feature branch and groups together
all commits that together added the feature.
15.
16. Release branches (1)
May branch off from develop
Must merge back into
develop
master
Branch naming convention: release-*
Tag: increment major or minor number
17. Release branches (2)
Release branches support preparation of a new
production release. They allow for last-minute
dotting of i’s and crossing t’s. Furthermore, they
allow for minor bug fixes and preparing meta-data
for a release (version number, build dates, etc.).
By doing all of this work on a release branch, the
develop branch is cleared to receive features for
the next big release.
18. Release branches (3)
The key moment to branch off a new release
branch from develop is when develop (almost)
reflects the desired state of the new release.
It is exactly at the start of a release branch that
the upcoming release gets assigned a version
number, not any earlier. Up until that moment, the
develop branch reflected changes for the “next
release”, but it is unclear whether that “next
release” until the release branch is started.
19. Hotfix branches (1)
May branch off from master
Must merge back into
develop
master
Branch naming convention: hotfix-*
20. Hotfix branches (2)
Hotfix branches are very much like release branches in that
they are also meant to prepare for a new production release,
albeit unplanned. They arise from the necessity to act
immediately upon an undesired state of a live production
version.
When a critical bug in a production version must be resolved
immediately, a hotfix branch may be branched off from the
corresponding tag on the master branch that marks the
production version.
The essence is that work of team members (on the develop
branch) can continue, while another person is preparing a
quick production fix.
21. Hotfix branches (3)
There is one exception to the merge rule, when a
release branch currently exists, the hotfix
changes need to be merged into that release
branch, instead of develop.
Back-merging the bugfix into the release branch
will eventually result in the bugfix being merged
into develop too, when the release branch is
finished.
22. Branches
branch number of branches
may be removed
after merge
master once forever never
develop once forever never
feature many at the same time —
release-name once at the same time yes
hotfix-name once at the same time yes
25. GitHub Flow (2)
GitHub Flow is a lightweight, branch-based
workflow that supports teams and projects where
deployments are made regularly.
Where regularly means teams deploy to
production every day, often several times a day
(Continuous Integration is required).
26. What is GitHub Flow? (1)
It is based on 6 simple rules:
(1) Anything in the master branch is deployable;
(2) To work on something new, create a
descriptively named branch off of master (ie:
suggested-channels);
(3) Commit to that branch locally and regularly
push your work to the same named branch on the
server;
27. What is GitHub Flow? (2)
It is based on 6 simple rules:
(4) When you need feedback or help, or you think
the branch is ready for merging, open a pull
request;
(5) After someone else has reviewed and signed
off on the feature, you can merge it into master;
(6) Once it is merged and pushed to “master”, you
can and should deploy immediately.
28. #1 Anything in the master
branch is deployable
This is basically the only hard rule of the system.
There is only one branch that has any specific and
consistent meaning and we named it master.
It’s incredibly rare that this gets rewound (the
branch is moved back to an older commit to revert
work). If there is an issue, commits will be
reverted or new commits will be introduced that
fixes the issue, but the branch itself is almost
never rolled back.
29. #1 Anything in the master
branch is deployable
The master branch is stable and it is always safe to
deploy from it or create new branches off of it.
If you push something to master that is not tested or
breaks the build, you break the social contract of the
development team. Every branch we push has tests
run on it and reported to the team, so if you haven’t run
them locally, you can simply push to a topic branch.
You could have a deployed branch that is updated only
when you deploy, but we don’t do that. We simply
expose the currently deployed SHA.
30. #2 Create descriptive
branches off of master
When you want to start work on anything, you
create a descriptively named branch off of the
stable master branch.
This has several advantages: one is that when
you fetch, you can see the topics that everyone
else has been working on. Another is that if you
abandon a branch for a while and go back to it
later, it’s fairly easy to remember what it was.
31. #3 Push to named branches
constantly
Another big difference from git-flow is that we
push to named branches on the server constantly.
Since the only thing we really have to worry about
is master from a deployment standpoint, pushing
to the server doesn’t mess anyone up or confuse
things, everything that is not master is simply
something being worked on.
It also make sure that our work is always backed
up in case of laptop loss or hard drive failure.
32. #4 Open a pull request at any
time
GitHub has an amazing code review system called pull
requests.
GitHub Flow uses the pull requests to review the code
long before you actually want to merge it into master for
deployment.
If you are stuck in the progress of your feature or branch
and need help or advice, or if you are a developer and
need a designer to review your work (or vice versa), or
even if you have little or no code but some screenshot
comps or general ideas, you open a pull request.
33. #5 Merge only after pull
request review
We don’t simply do work directly on master or
work on a topic branch and merge it in when we
think it’s done. We try to get signoff from
someone else in the company. This is generally a
+1 or emoji or “:shipit:” comment.
Once we get that, and the branch passes CI, we
can merge it into master for deployment, which
will automatically close the pull request when we
push it.
34. #6 Deploy immediately after
review
Finally, your work is done and merged into the
master branch. This means that even if you don’t
deploy it now, people will base new work off of it
and the next deploy, which will likely happen in a
few hours, will push it out. So since you really
don’t want someone else to push something that
you wrote that breaks things, people tend to make
sure that it really is stable when it’s merged and
people also tend to push their own changes.
41. Pull request (1)
Pull requests are a feature that makes it easier for
developers to collaborate.
In their simplest form, pull requests are a
mechanism for a developer to notify team members
that they have completed a feature. Once their
feature branch is ready, the developer files a pull
request.
This lets everybody involved know that they need to
review the code and merge it into the master branch.
42. Pull request (2)
But, the pull request
is more than just a
notification. It’s a
dedicated forum for
discussing the
proposed feature. If
there are any
problems with the
changes,
teammates can post feedback in the pull request and
even tweak the feature by pushing follow-up
commits. All of this activity is tracked directly inside
of the pull request.
43. What is a pull request?
When you file a pull request, all you’re doing is requesting
that another developer pulls a branch from your repository
into their repository.
This means that you need to provide 4 pieces of information
to file a pull request:
• source repository
• source branch
• destination repository
• destination branch
44. Look out
A pull request requires either two distinct
branches or two distinct repositories.
45. A pull request using Bitbucket
This is the most simple Workflow:
• A developer creates the feature in a dedicated branch in their
local repo.
• The developer pushes the branch to a public Bitbucket
repository.
• The developer files a pull request via Bitbucket.
• The rest of the team reviews the code, discusses it, and alters
it.
• The project maintainer merges the feature into the official
repository and closes the pull request.
46. Accept a pull request
Only a user with write permissions on the
destination repository can accept or reject a pull
request. Any user with read permission in a
repository can review the open, accepted and
rejected pull requests.
47. Decline a pull request
Declining a pull request cannot be undone. Once
you decline a pull request you will have to open a
new pull request request to continue a review.
Declining a pull request has no effect on the
branches (source or destination) so the changes
in the source branch are still in that source
branch.