새소식

300x250
2. 웹개발/Error모음

[ Git ] git cannot lock, cannot lock ref, cannot create 에러

  • -
728x90

 

1. 에러 로그

 - 간혹 브랜치 생성 또는 Push 시 다음과 같은 유형의 에러메세지가 발생하며, 브랜치 생성 또는 Push가 불가능한 경우가 있다.

cannot lock ref 'refs/heads/...' 'refs/heads/...' exists cannot create 'refs/heads/...'

 

 - 보통은 다음과 같이 특정 분기/하위 브랜치를 생성하려고 시도하는 경우에 봤을 것 이다.

ex) 

## feature
cannot lock ref 'refs/heads/feature/branchname' 'refs/heads/feature' exists cannot create 'refs/heads/feature/branchname'

## hotfix
cannot lock ref 'refs/heads/hotfix/branchname' 'refs/heads/hotfix' exists cannot create 'refs/heads/hotfix/branchname'

## release
cannot lock ref 'refs/heads/release/branchname' 'refs/heads/release' exists cannot create 'refs/heads/release/branchname'

 

2. 해결 방법

 

 - 분기 "X"가 존재하는 경우 "X/branchname" 같이 하위 분기를 생성할 수 없다는 것이므로 "X"분기, 브랜치가 존재하는지 확인해 보자.

 - 마찬가지 브랜치 dev/b존재하는 경우 dev/b/c생성도 불가능 하다.

 

※ 오리진에 해당 브랜치(ex "dev/b")를 생성하려고 한다면  "dev" 분기를 먼저 삭제 해야 한다.

 

1. 정말 불필요한 브랜치라면 삭제하면 바로 해결 가능 하다.

 

2. 혹시 위의 경우같이 하위 분기가 없는데도 위와같은 오류가 발생하는 경우 

    존재하지 않는 원격 브랜치에 대한 정보가 남아 있어서 가져오지도 못하는 상태인 경우도 있다고 한다.

 - 참고 : https://stackoverflow.com/questions/22630404/git-push-refs-heads-my-subbranch-exists-cannot-create

ex) 

error: cannot lock ref ‘refs/remotes/origin/{branch_name}’: ‘refs/remotes/origin/{branch_prefix}’ exists; 
cannot create ‘refs/remotes/origin/{branch_name}’

 

 

 - 이경우 다음 방법을 사용했다고 하니 참고 차 기록해 두려 한다. 

git gc --prune=now
git remote prune origin

 

방법 1) git-gc - 불필요한 파일을 정리하고 로컬 저장소를 최적화 한다.

https://git-scm.com/docs/git-gc


방법 2) git-prune - 개체 데이터베이스에서 연결할 수 없는 모든 개체를 정리 한다..

https://git-scm.com/docs/git-prune

 

 

300x250
Contents

포스팅 주소를 복사했습니다

이 글이 도움이 되었다면 공감 부탁드립니다.