diff options
Diffstat (limited to 'bin')
| -rwxr-xr-x | bin/git-other-branches | 12 | ||||
| -rwxr-xr-x | bin/git-update-all | 20 |
2 files changed, 32 insertions, 0 deletions
diff --git a/bin/git-other-branches b/bin/git-other-branches new file mode 100755 index 0000000..034670e --- /dev/null +++ b/bin/git-other-branches @@ -0,0 +1,12 @@ +#!/usr/bin/env bash + +GITBIN='/usr/bin/git' +AWKBIN='/usr/bin/awk' +GREPBIN='/usr/bin/grep' + +# 1. Pull the current branch and also tags, and prune references vanished from remote +# shellcheck disable=SC2016 +"$GITBIN" branch --remotes |\ + "$AWKBIN" '{print $1}' | "$AWKBIN" -F/ '{print $2}' |\ + "$GREPBIN" -v "^$(git rev-parse --abbrev-ref HEAD)\$" |\ + "$GREPBIN" -v '^HEAD$' diff --git a/bin/git-update-all b/bin/git-update-all new file mode 100755 index 0000000..0855339 --- /dev/null +++ b/bin/git-update-all @@ -0,0 +1,20 @@ +#!/usr/bin/env bash + +GITBIN='/usr/bin/git' + +# 1. Pull the current branch and also tags, and prune references vanished from remote +"$GITBIN" pull -tpf || exit 110 +# 2. Pull all branches existing locally +if ! mybr="$("$GITBIN" symbolic-ref --short HEAD 2>/dev/null)"; then + printf 'Not on a branch, aborting.\n' >&2 +else + while read -r branch + do + ( + printf '\033[1m\033[3mSwitching to %b.\033[0m\n' "$branch" + "$GITBIN" switch "$branch" &&\ + "$GITBIN" pull &&\ + "$GITBIN" switch "$mybr" + ) + done < <("$GITBIN" for-each-ref --format='%(refname:short)' refs/heads/ | grep -vP "^${mybr}\$") +fi |
