I am writing a GitHub workflow where I am building documentation from the main branch docstrings and pushing it to gh-pages and having GitHub pages deploy off of gh-pages branch. How can I protect that branch so that only GitHub branches can push to it and not allow anyone else?
How can I protect a GitHub branch and allow only GitHub actions to push to it and no one else?
1.8k Views Asked by AugustusCaesar At
2
There are 2 best solutions below
0
Noah Hsu
On
I facing exactly the same use case in my repo,
after read the issue in the GitHub community, here comes my workaround as follow:
- Set two branch rules
- main : check "Require a pull request before merging" and "Require 1 approvals"
- gh-pages: check "Allow force pushes" and add yourself or an org-account to the "Specify who can force push"
- create a PAT of yourself or the org-account and save to repository secret (In Setting/Actions secrets and variables/Actions)
- add with token when checkout code in GHA:
steps: - uses: actions/checkout@v3 with: token: ${{ secrets.GH_TOKEN}} - in Settings/Actions permissions/Fork pull request workflows from outside collaborators, check
- "require approval for first-time contributors" or
- "require approval for all outside collaborators"
Related Questions in GITHUB
- How to update to the latest external Git in Azure Web App?
- Github Pages Deployment deploys a blank page
- Git Not In Sync with Local Branch
- How do I create a test passing badge for my yaml below
- Cant connect to any github repository from my netbeans 20
- How can i redirect pull request from main branch to another branch
- Trying to update the version.go file with the release tag from GitHub actions but its failing
- Encountering Errors Running GitHub Project: Wavelet-pixel domain progressive fusion network for underwater image enhancement - Seeking Assistance
- How can I reintroduce username an password on git using fedora?
- How do I find Github File_ID?
- Forking vs Cloning in GitHub
- I can't find ~/.profile or ~/.bashrc in C:/Users/<user>/.ssh folder
- how to build nextjs app unable to build and deploy
- Plugin with id 'com.android.application' not found in Github Winlator Project
- Git commit asks for passphrase which I don't remember
Related Questions in GITHUB-ACTIONS
- How do I create a test passing badge for my yaml below
- Driver com.microsoft.sqlserver.jdbc.SQLServerDriver claims to not accept jdbcUrl, ${SPRING_DATASOURCE_URL}: GitHub Actions
- Trying to update the version.go file with the release tag from GitHub actions but its failing
- While Running Github Actions Pipeline: No Signing Certificate "iOS Development" found: No "iOS Development" signing certificate matching team ID
- Gradle SAXParseException cvc-complex-type.2.4.a
- Unable to deploy to GAE from Github Actions
- Set environment variable during push for GitHub Actions
- Error: P1001: Can't reach database server at `db`:`5432` on github actions
- Android SafeArgs gives error with GitHub actions
- How to restore nuget from private github feed using Github App and no PAT?
- Github Actions/variable-mapper : Error: Unexpected token *** in JSON
- Github action Post Run fails workflow
- How to push multiple changes from matrix in Github Actions
- Display coverage report on browser
- Unable to use env variable from prd environment context
Related Questions in GITHUB-PAGES
- mp4 embedded videos within github pages website not loading
- Github Pages Deployment deploys a blank page
- How do I find Github File_ID?
- Tailwind CSS background image does not work on github pages
- Github ERROUploadArtifac -Next.js Project
- Hello please i have difficulties in setting up my Github account
- Github Pages with sveltekit only shows the HTML contents of app.html
- Why do I get this part when I try to publish my portfolio?
- Showing Error: Failed to get remote.origin.url when deploying react vite website using gh-pages
- quarto preview gives a slightly different website than github pages
- edge can not show github markdown list
- npm run deploy outputs "[email protected]: Permission denied (publickey)" with ssh key
- Auth0 Errors When Trying to Use it In Conjunction with Github Pages
- Difficulty in uploading images on GitHub
- how to have the allure report github pages for each environment?
Related Questions in MKDOCS
- Mkdocs Glossary Search returns one big paragraph
- Changing translation on GitHub page homepage with mkdocs-static-i18n results in a 404
- customizing logo in mkdocs and material
- yq deal with list items that can be values or objects
- How do I get doctest to run with examples in markdown codeblocks for mkdocs?
- MkDocs-with-pdf admonition icons on wrong position in pdf
- Material for MkDocs - activating Glightbox stops search field appearing
- Building documentation behind a symlink
- How to specify a file that can be downloaded via ReadTheDocs with MkDocs
- How can I setup a standalone techdocs documentation?
- How can I change the sidebar width in the desktop and mobile view properly?
- Transforming Nested Lists in R for YAML config
- Why in MKDocs project this error ERROR Config value 'nav': Expected nav to be a list, got None Aborted with 1 Configuration Errors
- Unable to render latex equations in .md files on mkdocs with mathjax support
- Issue building or serving mkdocs-material version 9.2 or higher showing jinja2 error
Related Questions in MKDOCS-MATERIAL
- Changing translation on GitHub page homepage with mkdocs-static-i18n results in a 404
- customizing logo in mkdocs and material
- MkDocs-with-pdf admonition icons on wrong position in pdf
- Building documentation behind a symlink
- How can I change the sidebar width in the desktop and mobile view properly?
- Why in MKDocs project this error ERROR Config value 'nav': Expected nav to be a list, got None Aborted with 1 Configuration Errors
- How can I include icons in Mermaid.js diagrams in Material for MkDocs?
- Issue building or serving mkdocs-material version 9.2 or higher showing jinja2 error
- Create pop ups using Mkdocs material Theme
- What set urls in lowercase and title not containing the site name?
- How to change the default config in MathJax?
- Mkdocstrings error "No module named" when using monorepo plugin
- Change Typescript Function to retrieve JSON data from Session Storage instead of a JSON file
- Can I influence the order of directories and pages in mkdocs/mkdocs-material manually?
- MKDocs rendering apostrophes in Markdown as ’
Trending Questions
- UIImageView Frame Doesn't Reflect Constraints
- Is it possible to use adb commands to click on a view by finding its ID?
- How to create a new web character symbol recognizable by html/javascript?
- Why isn't my CSS3 animation smooth in Google Chrome (but very smooth on other browsers)?
- Heap Gives Page Fault
- Connect ffmpeg to Visual Studio 2008
- Both Object- and ValueAnimator jumps when Duration is set above API LvL 24
- How to avoid default initialization of objects in std::vector?
- second argument of the command line arguments in a format other than char** argv or char* argv[]
- How to improve efficiency of algorithm which generates next lexicographic permutation?
- Navigating to the another actvity app getting crash in android
- How to read the particular message format in android and store in sqlite database?
- Resetting inventory status after order is cancelled
- Efficiently compute powers of X in SSE/AVX
- Insert into an external database using ajax and php : POST 500 (Internal Server Error)
Popular # Hahtags
Popular Questions
- How do I undo the most recent local commits in Git?
- How can I remove a specific item from an array in JavaScript?
- How do I delete a Git branch locally and remotely?
- Find all files containing a specific text (string) on Linux?
- How do I revert a Git repository to a previous commit?
- How do I create an HTML button that acts like a link?
- How do I check out a remote Git branch?
- How do I force "git pull" to overwrite local files?
- How do I list all files of a directory?
- How to check whether a string contains a substring in JavaScript?
- How do I redirect to another webpage?
- How can I iterate over rows in a Pandas DataFrame?
- How do I convert a String to an int in Java?
- Does Python have a string 'contains' substring method?
- How do I check if a string contains a specific word?
A new branch protection rule can be set up at
https://github.com/USERNAME/REPO/settings/branch_protection_rules/new. Any branch that has a matching name will be protected. The option "lock branch" will lock the branch and only allow admins to override and commit. Additionally, branch protection rules should be set up on main to require a pull request that way people cannot just push directly to main.