What are the differences between git remote prune, git prune, git fetch --prune, etc

前端 未结 4 1983
野趣味
野趣味 2020-11-27 09:06

My situation is this... someone working on the same repo has deleted a branch from his local & remote repo...

Most people who have asked about this kind of probl

4条回答
  •  粉色の甜心
    2020-11-27 09:18

    In the event that anyone would be interested. Here's a quick shell script that will remove all local branches that aren't tracked remotely. A word of caution: This will get rid of any branch that isn't tracked remotely regardless of whether it was merged or not.

    If you guys see any issues with this please let me know and I'll fix it (etc. etc.)

    Save it in a file called git-rm-ntb (call it whatever) on PATH and run:

    git-rm-ntb ...

    clean()
    {
      REMOTES="$@";
      if [ -z "$REMOTES" ]; then
        REMOTES=$(git remote);
      fi
      REMOTES=$(echo "$REMOTES" | xargs -n1 echo)
      RBRANCHES=()
      while read REMOTE; do
        CURRBRANCHES=($(git ls-remote $REMOTE | awk '{print $2}' | grep 'refs/heads/' | sed 's:refs/heads/::'))
        RBRANCHES=("${CURRBRANCHES[@]}" "${RBRANCHES[@]}")
      done < <(echo "$REMOTES" )
      [[ $RBRANCHES ]] || exit
      LBRANCHES=($(git branch | sed 's:\*::' | awk '{print $1}'))
      for i in "${LBRANCHES[@]}"; do
        skip=
        for j in "${RBRANCHES[@]}"; do
          [[ $i == $j ]] && { skip=1; echo -e "\033[32m Keeping $i \033[0m"; break; }
        done
        [[ -n $skip ]] || { echo -e "\033[31m $(git branch -D $i) \033[0m"; }
      done
    }
    
    clean $@
    

提交回复
热议问题