[Troubleshooting] git push -f 실패 (GH006)

2023. 1. 27. 16:19나는 이렇게 학습한다/Git

문제 원인

원격 저장소에 올라간 커밋을 되돌리기 위해 로컬에서 커밋을 되돌린 후에 강제로 push를 해야 하는데,

강제로 push 하는 명령어가 허용되지 않았다.

 

$ git push -f origin main
Total 0 (delta 0), reused 0 (delta 0), pack-reused 0
remote: error: GH006: Protected branch update failed for refs/heads/main.
remote: error: Cannot force-push to this protected branch
To https://github.com/WhatTheSong/WhatTheSong-Server.git
 ! [remote rejected] main -> main (protected branch hook declined)
error: failed to push some refs to 'https://github.com/WhatTheSong/WhatTheSong-Server.git'

해결 방안

기본적으로 브랜치는 강제로 push하는 명령어가 금지되어있다.

그래서 push 하려는 브랜치의 레포지토리 설정에 들어가서 강제로 push 하는 것을 허용시켜주어야 한다.

 

레포지토리 Settings > Branches > Branch protection rules 에서 푸시하고자 하는 브랜치 edit

아래쪽으로 스크롤 내려보면 Allow force pushes 라는게 있는데 이 부분을 체크해주어야 한다.

Everyone을 눌러 팀원 모두 허용시켜주거나, Specify who can force push를 선택해 특정한 팀원만 허용시키게 할 수도 있다.

참고 자료

https://computer-science-student.tistory.com/294

https://livealife.tistory.com/4

반응형