-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgit_branch_status
More file actions
executable file
·28 lines (24 loc) · 964 Bytes
/
git_branch_status
File metadata and controls
executable file
·28 lines (24 loc) · 964 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#!/usr/bin/env bash
# by http://github.com/jehiah
# this prints out some branch status (similar to the '... ahead' info you get from git status)
# example:
# $ git branch-status
# dns_check (ahead 1) | (behind 112) origin/master
# master (ahead 2) | (behind 0) origin/master
declare -a local_branches
while read -r local remote
do
if [ -z "$remote" ]
then
local_branches+=("$local")
continue
fi
git rev-list --left-right "${local}"..."${remote}" -- 2>/dev/null >/tmp/git_upstream_status_delta || continue
AHEAD=$(grep -c '^<' /tmp/git_upstream_status_delta)
BEHIND=$(grep -c '^>' /tmp/git_upstream_status_delta)
printf '%30s \x1b[33m(ahead %2s) \x1b[0m| \x1b[34m(behind %3s) \x1b[32m%s\x1b[0m\n' "$local" "$AHEAD" "$BEHIND" "$remote"
done < <(git for-each-ref --format="%(refname:short) %(upstream:short)" refs/heads)
for branch in "${local_branches[@]}"
do
printf '%s only exists locally\n' "$branch"
done