개발/Git
Github Action을 이용해서 다른 브런치에 머지
Seobs
2024. 1. 4. 10:30
상황
A브런치(branch-1)에 push가 되었을 경우 B브런치(branch-2)에도 똑같이 머지를 해야하는 경우가 생겼습니다.
개발
on:
push:
branches:
- branch-1
name: Merge to branch-2
jobs:
merge:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Merge to branch-2
run: |
git config user.name "GitHub Actions"
git config user.email "actions@github.com"
git checkout branch-2
git merge --allow-unrelated-histories branch-1 --no-ff --no-edit
git push origin branch-2
위 코드는 branch-1에 push가 생겼을때 git cehckout, merge, push를 통해 branch-2에도 똑같이 머지를 하는 방법입니다.
allow-unrelated-histories
github action에서 진행할 때 계속해서 refusing to merge unrelated histories 관련 에러가 났습니다.
아마 서로 관련 기록이 없어서 그런 것 같은데 그래서 --allow-unrelated-histories 옵션을 사용하게 되었습니다.
fetch-depth: 0
fetch-depth의 기본 값은 1입니다.
그렇게 되면 커밋 히스토리를 1개만 가져오기 때문에 전체를 가져오기 위해 0으로 설정을 하였습니다.
Push: Permission Denied
push를 하게 되면 보통 Permission Denied를 만나게 될 것입니다.
이는 github action에서 write 권한이 없어서 나타나는 상황입니다.
repository로 가서 Settings - Actions - Genereal - Workflow Permission을 가게 되면 Permission을 수정할 수 있습니다.
여기서 Read and write permissions 으로 선택하면 push를 할 수 있게 됩니다.