我想在我的团队中采用git-flow工具。
问题是,“git flow feature finish”会在本地合并分支。 而我想创建一个pull request代替。这样,合并将在远程仓库中进行。
那么,在与使用pull request的团队中使用git-flow工具的正确方法是什么?
尝试了谷歌搜索,但没有找到有意义的东西。
我想在我的团队中采用git-flow工具。
问题是,“git flow feature finish”会在本地合并分支。 而我想创建一个pull request代替。这样,合并将在远程仓库中进行。
那么,在与使用pull request的团队中使用git-flow工具的正确方法是什么?
尝试了谷歌搜索,但没有找到有意义的东西。
git flow feature publish
命令将您的功能分支发布到源头(例如Bitbucket)。然后,在那里创建拉取请求并将其合并到develop分支中。完成后,需要手动删除本地功能分支。git flow feature finish
。这种方法效果不错,您仍然可以使用大多数git flow助手。这个问题有一个很好的解决方案,但需要使用自定义脚本,因为PR API对每个平台都是独特的。
git-flow的AVH版本具有一些额外的功能: https://github.com/petervanderdoes/gitflow-avh
它支持挂钩(自定义脚本): https://github.com/petervanderdoes/gitflow-avh/wiki/Reference:-Hooks-and-Filters#hooks
您可以在Mac上切换到AVH版本:
brew uninstall git-flow
brew install git-flow-avh
.git/hooks/post-flow-feature-publish.sh
这是一个示例脚本post-flow-feature-publish.sh
,用于输出一个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
如果您使用GitHub CLI,则可以调用:gh pr create
。https://cli.github.com/manual/gh_pr_create
现在运行命令时:
git flow feature my-feature publish
Git flow会将代码推送到功能分支,并调用挂钩脚本来创建PR。
post-flow-feature-publish.sh
脚本?并不是大多数人都熟悉 Github REST API。 - oligofren.git/hooks/post-flow-feature-publish.sh
文件,并添加命令以创建GitHub PR。如果使用GitHub CLI,您应该能够调用:gh pr create
https://cli.github.com/manual/gh_pr_create - Kim Tgit flow feature start my-feature
git flow feature publish my-feature
git checkout develop && git pull
git flow feature finish my-feature
。它将从本地和远程仓库中删除'my-feature'分支。