Github Protected Branches with GitFlow
Asked Answered
A

2

27

I've got a repository with my develop branch protected and I'm using the GitFlow branching model. There's two branches; develop (containing features currently being developed) and master (latest deployed production code).

My develop branch prevents commits being directly made via GitHub's Protected branches. When you locally finish a hotfix using GitFlow, it automatically merges the hotfix branch into your local master and develop branches. However, pushing changes directly on the develop branch are not permitted as this is a protected branch

How can you overcome this? At the minute everytime I am creating a hotfix I have to:

  1. Manually turn off the branch protection
  2. Push the develop branch
  3. Turn it back on

This is not automated and therefore, not really acceptable.

Applicator answered 7/3, 2017 at 14:54 Comment(6)
Hi! Did my answer help you by any chance? Or did you find a solution in the meantime?Gynecoid
There is currently no solution, still.Applicator
And my answer didn't help you aswell?Gynecoid
Nope, because you have to turn off branch protection nor does it use the same branch structure as Gitflow.Applicator
No you don't have to turn it off... But ok.Gynecoid
The commands can be limiting. Deploy the hotfix first. Then create a PR from hotfix/* to main / master and to develop and let the team approve.Ellon
E
0

Are you the owner of the GitHub project and do you have the administrator role setup with your account (or can you grant administrator access to your account)?

In this case I would recommend you not to protect the branch for administrators. This way you can guarantee that other persons are not pushing directly to develop, but all "knowledged devs" with administrator access are able to. They should be aware of what they are doing, though.

You can edit this behaviour under https://github.com/${name}/${repo}/settings/branches/. My settings do look like this (the last checkbox is important):

Github Branch protection settings example

Note: maybe you could also use the "Restrict who can push to this branch" option.

Elkin answered 13/7, 2017 at 16:12 Comment(4)
That is not really a solution in my opinion, as people protect their branches for a reason. To bypass that is to negate those choices.Miscreated
I know what you mean @Miscreated and I would agree. If your branches are protected from everybody on the team you would most likely not use gitflow but another way to review and merge your changes. However, the OP seems to be the admin of the repo, since he can change the restrictions manually. So I assumed he wants to have protected branches for other contributors, but also wants to use gitflow for himself. In this case my proposal is (afaik) the only option.Elkin
Yeah it is a fine workaround. We are however also searching for a solution that works with these Github branch restrictions and the git flow commandline tool or concept.Miscreated
This is not a solution as develop and main/master branches should be protected.Tintinnabulation
B
0

Enable 'Require pull-requests' on GitHub.

After you merge the hotfix in your local master you can create a hotfix branch from it, to create a pull-request in origin. Your master will be different, but you can reset and stash and pull in the origin/master.

git checkout -b hotfix
git push origin hotfix
# merge
git checkout master
git reset origin/master
git stash
git pull --rebase
Breather answered 22/1, 2020 at 15:18 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.