utinome
utinome

Reputation: 561

Proper way to use Gitflow with pull requests

I would like to adopt the git-flow tool inside my team.

The problem is that "git flow feature finish" merges the branches locally. And I want to create a pull request instead. Thus, the merge will happen in the origin.

So, what is the right way to use the git-flow tool in teams that also work with pull requests?

Tried to google it but could not find something meaningful.

Upvotes: 56

Views: 26261

Answers (4)

Peter Centellini
Peter Centellini

Reputation: 1565

Old thread but I thought I give it my 2 cents anyway.

In our team we have the following workflow with Git Flow in SourceTree:

  1. Go to your develop branch
  2. Click on the Git Flow button
  3. Choose 'Start New Feature'
  4. Choose a Feature name and make sure you branch from develop, then click OK
  5. Do your work on the Feature branch
  6. When done with the Feature, in SourceTree go to the menu choice Repository -> Create Pull Request
  7. In the pop-up the comes up choose 'Create Pull Request On Web'
  8. The Bitbucket web page opens and there you choose to make a PR and choose your reviewers
  9. When the merge is accepted by the reviewers, go to your feature in SourceTree
  10. Click on the Git Flow button and choose Finnish Feature

Upvotes: 0

Yaser Khahani
Yaser Khahani

Reputation: 705

  1. Start your feature branch: git flow feature start my-feature
  2. Develop the feature and commits related changes.
  3. Publish the feature: git flow feature publish my-feature
  4. Go to for example Gitlab and create merge-request, review and merge it (DO NOT DELETE the source/feature branch).
  5. Checkout to 'develop' and pull all changes from remote origin: git checkout develop && git pull
  6. Final step, finish the feature: git flow feature finish my-feature. It will be deletes 'my-feature' branch both from local and remote.

Upvotes: 2

Kim T
Kim T

Reputation: 6416

There is a great solution to this problem, but it does require a custom script since PR APIs are unique to each platform.

The AVH version of git-flow has some additional features: https://github.com/petervanderdoes/gitflow-avh

It has support for hooks (custom scripts): https://github.com/petervanderdoes/gitflow-avh/wiki/Reference:-Hooks-and-Filters#hooks

You can swap to the AVH version on a Mac using:

brew uninstall git-flow
brew install git-flow-avh

To support a pull request in git flow you can add a script:

.git/hooks/post-flow-feature-publish.sh

Example post-flow-feature-publish.sh script to output a url:

#!/bin/sh

branch=$(git rev-parse --abbrev-ref HEAD)
userRepo=$(git remote -v | grep fetch | awk '{print $2}' | grep "github.com" | cut -d':' -f2 | rev | cut -c5- | rev)

if [ -n "$userRepo" ]
then
    echo ""
    echo "Create PR at: https://github.com/$userRepo/compare/$branch?expand=1"
    echo ""
fi

Or if using the GitHub CLI you could call: gh pr create https://cli.github.com/manual/gh_pr_create

Now when running the command:

git flow feature my-feature publish

Git flow will push code to the feature branch and call the hook script to create the PR.

Upvotes: 5

PWFraley
PWFraley

Reputation: 1082

You can just use the git flow feature publish <name>this will publish your feature branch to your origin (like Bitbucket). Then you can create the pull request there and merge it into develop. After that is done, you need to manually delete the local feature branch.

The only command you can not use is git flow feature finish <name>. This works fairly well and you can still use most of the git flow helpers.

The same goes for releases. I found this article helpfull: https://blog.axosoft.com/pull-requests-gitflow/

As well as https://community.atlassian.com/t5/Bitbucket-questions/git-flow-feature-finish-and-pull-request/qaq-p/347877

Hope this helps a little. There is just not the one perfect solution to this problem.

Upvotes: 56

Related Questions