[Git] How to push branch to remote branch applied protection rules in actions
3 min readMar 1, 2022
main 브랜치에 hotfix를 merge 할 때, 자동으로 dev 브랜치에도 머지하고 싶은데 branch protection rule 때문에 안되서 방법을 찾다가 완전하지는 않지만 아쉬운대로 쓸 수 있는 정도로 접근했다.
setting에서 personal token을 발급 받아, secret actions에 “ADMIN_TOKEN”으로 등록하고 아래와 같이 actions yml을 추가해두면 동작한다.
name: Back merge from main to devon: pull_request_target: branches: [main] types: - closed workflow_dispatch:jobs: merge-main-back-to-dev: if: github.event.pull_request.merged == true && startsWith(github.head_ref, 'hotfix/') timeout-minutes: 2 runs-on: ubuntu-latest steps: - name: checkout uses: actions/checkout@v2 with: token: ${{ secrets.ADMIN_TOKEN }} - name: Set Git config run: | git config --local user.email "actions@github.com" git config --local user.name "Github Actions" - name: Merge main back to dev run: | git fetch --unshallow git switch dev git pull git merge --no-ff main -m "Auto-merge main back to dev" git push
위 조건 때문에 actions에서 push 를 못하는 것인데, 검색해보면 이 문제로 많이들 고통 받고 있다. 위 스크립트가 동작하려면 아래 Include administrators는 체크하면 안된다.
참고(출처): https://github.community/t/how-to-push-to-protected-branches-in-a-github-action/16101/35?page=2