Created
October 2, 2017 17:38
-
-
Save AWhetter/19aa411c35cf08a1e670c66aba914ce3 to your computer and use it in GitHub Desktop.
fetchout subcommand for git that fetches and checks out the new branch
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
#!/bin/bash | |
get_branches() { | |
git branch -r | tail -n +2 | sed "s|^[^/]*/||" | sort | |
} | |
branches_were=$(get_branches) | |
git fetch | |
branches_are=$(get_branches) | |
mapfile -t choices < <(diff --old-line-format="" --unchanged-line-format="" <(echo "$branches_were") <(echo "$branches_are")) | |
if [ ${#choices[@]} -eq 1 ] | |
then | |
git checkout "${choices[0]}" | |
exit 0 | |
elif (( ${#choices[@]} )) | |
then | |
echo | |
select branch in "${choices[@]}" | |
do | |
git checkout "$branch" | |
exit 0 | |
done | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment