A place to understand how to use Pull Requests with git-flow.
We assume the following:
- You have git flow (AVH Edition) installed,
- You have Github's CLI installed.
The example app is written in Go, but it does not really matter as we will not even compile it.
For instructions using Bitbucket, please go to the Bitbucket repository.
For instructions using GitLab, please go to the GitLab repository.
Using gh, let's clone this sandbox:
gh repo clone gildas/gitflow-pr-sandbox
Once inside the repository, initialize git flow:
git flow init
Make sure to:
- name the
develop
branchdev
(I never liked that long label) - set the version tag prefix to
v
If you want to use my git flow hooks, go to its folder, and initialize the hooks with the path of your repository folder:
./hook-it ~/Documents/path/to/gitflow-pr-sandbox
This will initialize git flow, and copy the appropriate hooks.
Let's start our feature:
git flow feature start myfeature
Add and commit some changes...
You can share the feature with fellow developers by pushing the branch to the repository (do not use git flow feature publish
since we will use it to create the Pull Request).
git push --set-upstream origin feature/myfeature
or
git push -u origin feature/myfeature
Once the feature is finished, publish the feature:
git flow feature publish myfeature
If you use my git flow hooks, the Pull Request will be automatically created.
Otherwise, create the Pull Request:
gh pr create \
--title "Merge feature myfeature" \
--body "Feature myfeature" \
--base dev
Now, as the Pull Request reviewer, log on github and merge the Pull Request without deleting the feature branch. Or use the CLI:
gh pr merge \
--subject 'Merged feature myfeature'
Back to the feature owner, grab the merge:
git checkout dev
git pull
And finish the feature:
git flow feature finish myfeature
Since preparing a release usually involves the master branch, typically, the people that take care of that task are usually the maintainers of the project.
Let's start a new release:
git flow release start 1.0.0
If you use my git flow hooks, you will get the auto-versioning for node.js and Go based projects.
If not, you should modify your project's version manually, in the current case:
sed -Ei '/VERSION\s+=/s/[0-9]+\.[0-9]+\.[0-9]+/1.0.0/' version.go
git add version.go
git commit -m "Bumped to version 1.0.0" version.go
You can also share the release branch with others by pushing it to the repository (like features):
git push -u origin release/1.0.0
When all bugs have been fixed and the QA process is done, the release should be published to created a Pull Request:
git flow release publish
If you use my git flow hooks, the Pull Request will be automatically created.
Otherwise, create the Pull Request:
gh pr create \
--title "Merge release 1.0.0" \
--body "Release 1.0.0." \
--base master
Now, as the Pull Request reviewer, log on github and merge the Pull Request without deleting the release branch. Or use the CLI:
gh pr merge \
--subject 'Merged release 1.0.0'
Back to the release baker, grab the merge:
git checkout master
git pull
And finish the release:
git flow release finish 1.0.0
Let's start a new hotfix:
git flow hotfix start 1.0.1
If you use my git flow hooks, you will get the auto-versioning for node.js and Go based projects.
If not, you should modify your project's version manually, in the current case:
sed -Ei '/VERSION\s+=/s/[0-9]+\.[0-9]+\.[0-9]+/1.0.1/' version.go
git add version.go
git commit -m "Bumped to version 1.0.1" version.go
You can also share the hotfix branch with others by pushing it to the repository (like features and releases):
git push -u origin hotfix/1.0.1
When all bugs have been fixed and the QA process is done, the hotfix should be published to created a Pull Request:
git flow hotfix publish
If you use my git flow hooks, the Pull Request will be automatically created.
Otherwise, create the Pull Request:
gh pr create \
--title "Merge hotfix 1.0.1" \
--body "Hotfix 1.0.1" \
--base master
Now, as the Pull Request reviewer, log on github and merge the Pull Request without deleting the hotfix branch. Or use the CLI:
gh pr merge \
--subject 'Merged hotfix 1.0.1'
Back to the hotfix maker, grab the merge:
git checkout master
git pull
And finish the hotfix:
git flow hotfix finish 1.0.1