gloriaJun / til

Lessoned Learned
3 stars 0 forks source link

[git] Protect Main Branch to push directly #122

Open gloriaJun opened 3 years ago

gloriaJun commented 3 years ago

master / develop / releaes와 같은 메인 브랜치로의 반영을 PR을 통하여 반영하는 경우, 실수로!! 해당 브랜치에 push하는 것을 git branch rule을 이용하여 예방할 수 있습니다.

단!! 해당 기능은 organization에 속한 repository에서만 사용 가능 합니다.

github project - settings - branches - add rule을 이용하여 규칙을 적용하고자 하는 브랜치를 설정 후에 아래의 옵션을 설정하면 됩니다. image

위와 같이 설정을 하면 해당 규칙이 설정된 브랜치에 대해 아래와 같이 1개의 커밋 내역이 로컬 브랜치에 존재하는 상황에서...

❯ git lh 2  
* 6f202561aa - (HEAD -> release/push-test) test: push test (2021-05-27)<****>
*   4ab412e4bb - (upstream/release/push-test, upstream/develop, develop) Merge branch 'release/phase-1.3' into develop (2021-05-27)<****>

해당 브랜치로 바로 push를 하고자 하는 경우, 다음과 같이 에러가 발생하게 되어 미연에 실수로 해당 브랜치로 push하는 것을 예방할 수 있습니다.

❯ git push                   
오브젝트 나열하는 중: 4, 완료.
오브젝트 개수 세는 중: 100% (4/4), 완료.
Delta compression using up to 12 threads
오브젝트 압축하는 중: 100% (2/2), 완료.
오브젝트 쓰는 중: 100% (3/3), 274 bytes | 68.00 KiB/s, 완료.
Total 3 (delta 1), reused 1 (delta 0), pack-reused 0
remote: Resolving deltas: 100% (1/1), completed with 1 local object.
remote: error: GH006: Protected branch update failed for refs/heads/release/push-test.
remote: error: 3 of 3 required status checks are expected. Waiting on code owner review from ****.
To <repo name>
 ! [remote rejected]       release/push-test -> release/push-test (protected branch hook declined)
error: 레퍼런스를 '<repo name>'에 푸시하는데 실패했습니다

참고 글 : https://roseline.oopy.io/dev/branch-pr-convention