협업/git

Git Prune 에 대해 알아보자

피고녀 2020. 8. 26. 23:47

git pull (fetch) 과정에서 ref lock 에러를 마딱뜨렸는데,

이 때 해결방법중 하나가 'git remote prune origin' 을 수행하는 것이라 한다.

그래서 이 녀석의 정체에 대해 알아보고자 한다.

$ git remote prune origin

 

 

git prune 은 unreachable 한 git object 들을 "local" 에서 clean 하는 작업이다.

unreachable 이란 git tree 에 의해 참조되지 않는 gc 대상이 되는 dangling refs 들이다.

 

 

git prune 은 보통 직접 수행되지 않는다.

이 녀석은 git gc 의 child command 이다.

 

 

git prune 을 수행할 때 --dry-run --verbose 옵션을 주면 실제 수행되지는 않고, 어떻게 수행될지 시뮬레이션을 볼 수 있다.

$ git remote prune --dry-run --verbose

 

 

git remote prune 과 git fetch --prune 도 git prune 이 하는 일을 똑같이 한다.

remote 에 존재하지 않는 refs 를 지워버린 후에 fetch 나 pull 을 수행한다.

$ git fetch --prune

 

 

prune 은 remote 의 것을 지우는 것이 아닌, local 에서 remote 를 ref 하는 것 중 유효하지 않은 것을 제거하는 작업이다.



출처: https://aroundck.tistory.com/6529 [돼지왕 왕돼지 놀이터]