본문 바로가기
Tools/Git

[Git] Your branch is ahead of 'origin/main' by 2 commits. 해결 방법

by Jay Son 아기 냥이 해린 짱💖 2021. 7. 15.

원인 : push 되지 않은 commit 이 2개 생성되어 있음.

해결 방법 : 중복 생성된 commit 을 삭제하고 1개씩 push 

 

git push 실행시 error: src refspec master does not match any 발생

$git push grigin master

 

git status 명령어로 에러 원인 확인 

친절하게 Your branch is ahead of 'origin/main' by 2 commits. 가이드 문구 표시

$git status

 

git log 명령어로 현재 commit 상태 확인

아래와 같이 origin/main 까지 push commit 이후 2개 commit이 생성되어 있음.

$git log

 

git reset을 이용해서 가장 최근 commit 삭제

reset 실행 후 git log 확인 결과 아래와 같이 최근 commit 삭제 확인 가능

git reset HEAD^

 

$ git push origin main

 

일반적인 구글링 했을 경우 해결 방법

나의 경우 위 캡쳐 내용에서도 확인 가능하듯이 내가 생성한 branch에는 master branch가 존재 하지 않음.

git push origin master -> git push origin main 으로 push 할 경우 commit 2개 생성되어 있더라도 정상 push 가능.

 

git branch 실행 할 경우 아래와 같이 main branch만 존재하는 것을 확인 할 수 있다.

$git branch

 

반응형