etc.

git push가 안 될 때 / detached HEAD 문제 해결 방법

공대 아로마 2020. 11. 9. 18:54

git을 아직도 잘 못 다루는 것 같다.

맨날 하는 add/commit/push/pull은 쉽게 사용하지만,

과거 commit으로 checkout했다가 다시 불러오고 하다보면 꼭 문제가 생긴다.

 

오늘의 문제는 detached HEAD라면서 remote repository에 push가 되지 않았다.

이미 commit은 해버렸는데..?

 

그럴 때 해결 방법은 임시로 branch를 만드는 방법이다.

 

git branch temp
git checkout temp

이렇게 하면 temp라는 branch가 만들어지고, temp로 checkout을 하게 된다.

 

git branch -f master temp
git checkout master

-f 옵션은 force를 하겠다는 이야기, 즉 강제로 실행하라는 것이다.

 

이런 메시지가 나오면 어느 정도 성공이다.

 

git branch -d temp

임시로 만든 temp라는 branch는 지운다.

 

git push

마지막으로 push해주면 끝이다.

 


참고: https://stackoverflow.com/questions/5772192/how-can-i-reconcile-detached-head-with-master-origin