Skip to content

Instantly share code, notes, and snippets.

@russelldavis
Created April 29, 2014 23:07
Show Gist options
  • Save russelldavis/e5173ce1269fae67baaf to your computer and use it in GitHub Desktop.
Save russelldavis/e5173ce1269fae67baaf to your computer and use it in GitHub Desktop.
A better git-checkout
#!/bin/bash
#####
# Fix the ridiculous ambiguity between branches and files in git-checkout.
# The new default behavior is to check out branches only.
# To check out a file, you must precede the filename with "--".
#####
found=false
for arg in "$@"; do
if [[ $arg == "--" ]]; then
found=true
break
fi
done
if ! $found; then
# Add "--" to the end (the first "--" is for the set command itself)
set -- "$@" --
fi
exec git checkout "$@"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment