usage:
git-remote-list-prune
git-remote-prune
git-remove-list-untracked
git-remove-untrackedor interactively:
do_git_remove_untrackedusage:
git-remote-list-prune
git-remote-prune
git-remove-list-untracked
git-remove-untrackedor interactively:
do_git_remove_untracked| # for zsh in macos, linux may need to change something | |
| alias git-remove-list-untracked='git fetch --prune && git branch -r | awk "{print \$1}" | egrep -v -f /dev/fd/0 <(git branch -vv | grep origin) | awk "{print \$1}"' | |
| # for squashed merged PRs | |
| alias git-remove-untracked='git fetch --prune && git branch -r | awk "{print \$1}" | egrep -v -f /dev/fd/0 <(git branch -vv | grep origin) | awk "{print \ | |
| $1}" | xargs git branch -D' | |
| # for non-squashed merged PRs | |
| #alias git-remove-untracked='git fetch --prune && git branch -r | awk "{print \$1}" | egrep -v -f /dev/fd/0 <(git branch -vv | grep origin) | awk "{print \ | |
| $1}" | xargs git branch -D' | |
| alias git-remote-list-prune='git remote prune --dry-run origin' | |
| alias git-remote-prune='git remote prune origin' | |
| do_git_remove_untracked() { | |
| # Array of commands and their descriptions | |
| local commands=( | |
| "git-remote-list-prune:List and prune remote branches" | |
| "git-remote-prune:Prune stale remote branches" | |
| "git-remove-list-untracked:List untracked files for removal" | |
| "git-remove-untracked:Remove untracked files" | |
| ) | |
| for cmd in "${commands[@]}"; do | |
| local command="${cmd%%:*}" # Extract the command | |
| local description="${cmd#*:}" # Extract the description | |
| while true; do | |
| echo -n "Do you want to run '${command}' (${description})? [y/n]: " | |
| read yn | |
| case $yn in | |
| [Yy]* ) | |
| echo "Running: $command" | |
| eval $command | |
| break | |
| ;; | |
| [Nn]* ) | |
| echo "Skipped: $command" | |
| break | |
| ;; | |
| * ) | |
| echo "Please answer y or n." | |
| ;; | |
| esac | |
| done | |
| done | |
| } |