내가이 일을 발견하는 방법은 다음과 같습니다 물론
git branch -a --contains name_of_local_branch | grep -c remotes/origin
, origin
은 어떤 원격의 이름을 변경할 수 있습니다.
이렇게하면 로컬 분기를 포함하는 원격 분기 번호가 출력됩니다. 이 숫자가 0과 다른 경우 로컬 저장소에서 정리하는 것이 좋습니다.
#!/bin/bash
# Find (/delete) local branches with content that's already pushed
# Takes one optional argument with the name of the remote (origin by default)
# Prevent shell expansion to not list the current files when we hit the '*' on the current branch
set -f
if [ $# -eq 1 ]
then
remote="$1"
else
remote="origin"
fi
for b in `git branch`; do
# Skip that "*"
if [[ "$b" == "*" ]]
then
continue
fi
# Check if the current branch tip is also somewhere on the remote
if [ `git branch -a --contains $b | grep -c remotes/$remote` != "0" ]
then
echo "$b is safe to delete"
# git branch -D $b
fi
done
set +f
이 자동 해결책이 아니다,하지만 당신은 항상 각 원격 지사에 대해 실행할 수는'자식 분기/remotebranch'에 원산지 --merged :
업데이트, 스크립트로했다 '원격 브랜치 (remotebranch) '의 헤드에서 접근 할 수있는 로컬 브랜치를 나열한다. – Jubobs
감사합니다 @ 주봉스, 저를 올바른 길로 인도합니다 ... – Matthieu