Branch protection using GitHub
In the past I pushed to the main
branch for every repository I have. I have done this for software projects but also for my publications. However, software projects should never push directly to main
. This one example of a best practice in software engineering.
I now focus on following more best practices in my software projects. Therefore, I protect the main
branch. I use a development
branch and specific branches for each feature.
Adapt process to writing publications?
When writing publications in LateX, I did not use feature branches. I though that such a process would be overkill. This resulted in some positive but also negative aspects.
Positive:
- Faster compared to branches. Just push and forget
- Only one branch. Clearer when I just work on a publication
Negative:
main
branch might have issues / bugs- Rollback to other states of the paper is harder. I can’t just remove one featuer (i.e. chapter)
- I have not overview on the current state of the paper. What am I currently working on? What is still missing? What have I done?
What do I do now?
Due to the stated negative aspects, I never push to the main
branch anymore. This results in a bit more work, but I think that the positive aspects of this new process are more valuable.
Hence, I have a main
branch that is always correct and holds the current version of my paper. New features (i.e. chapters or processes like grammer checks) are branches. This allows me to separate my tasks and clearly see what I did and what is still missing. In addition, I use GitHub’s issues feature to document tasks I still need to do or bugs I identify.
How to protect branches in GitHub?
- Go to
Settings
→Branches
- Click on
Add rule
- Add the name of the branch you want to protect. In this case it’s
main
- Check the settings
Require a pull request before merging
andInclude administrators
- Uncheck
Require approvals
underRequire a pull request before merging
- Click
Create