Last active
August 29, 2015 14:15
-
-
Save gregsexton/c4ce7ba0823b560a6e79 to your computer and use it in GitHub Desktop.
git-tldr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
if ! git rev-parse --git-dir > /dev/null 2>&1; then | |
echo "Not in a git repository." | |
exit 1 | |
fi | |
head_log_line=$(git log --pretty='%d %s' HEAD -1) | |
if current_branch=$(git symbolic-ref -q HEAD); then | |
echo "[X] On ${current_branch##refs/heads/}:$head_log_line" | |
else | |
echo "[ ] Dangling HEAD:$head_log_line" | |
fi | |
if test -n "$(git status --porcelain)"; then | |
echo "[ ] Repo is not squared away (run git status)" | |
fi | |
while read branch; do | |
upstream=$(git rev-parse --abbrev-ref $branch@{upstream} 2>/dev/null) | |
if [[ $? == 0 ]]; then | |
local=$(git rev-parse $branch) | |
remote=$(git rev-parse $branch@{upstream}) | |
base=$(git merge-base $branch $branch@{upstream}) | |
if [ $local = $remote ]; then | |
echo "[X] $branch -- $upstream" | |
elif [ $local = $base ]; then | |
echo "[ ] $branch -- $upstream (need to pull)" | |
elif [ $remote = $base ]; then | |
echo "[ ] $branch -- $upstream (need to push)" | |
else | |
echo "[ ] $branch -- $upstream (diverged)" | |
fi | |
else | |
echo "[ ] $branch -- (no tracking branch)" | |
fi | |
done < <(git for-each-ref --format='%(refname:short)' 'refs/heads/*') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is a very simple script for getting a quick view of the status of a git repo. It outputs only the info that I think is useful and does so in a very dense and scannable form. This tool is highly opinionated and suited to my particular workflow. I also tried git-wtf.
For best results loop over your git repos first with
git fetch --all
and then withgit tldr
.These were the design notes I made before writing it: