Created
June 23, 2022 18:02
-
-
Save DavidBiesack/6df5bb969c37b7dd587b97589393757a to your computer and use it in GitHub Desktop.
git-check-out.sh
This file contains hidden or 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
# My `git checkout` command. My `gb` (git branch) alias emits `co` commands as part of stdout: | |
# | |
# $ gb | |
# co 2022-06-21 09:59:27 -0400 bug/CUI-437-achPaymentInstruction-composition | |
# co 2022-06-21 09:49:16 -0400 * feature/CUI-304-wire-transfer-payment | |
# co 2022-06-16 18:25:32 +0000 master | |
# | |
# so I can use this `co` command to quicky check out a branch from within | |
# a comint shell buffer in Emacs by clicking on the desired line and pressing | |
# Enter to execute that line as a shell command | |
# If arg 1 looks like a date (i.e output of my `gb` git branch alias in ../config/.alias such as | |
# co 2022-06-13 14:10:27 -0400 * feature/ADB-171-add-ADB | |
# co 2022-04-01 13:32:04 +0000 master | |
# then throw out 3 args (date, time, zone). If next arg is *, shift it out. Then checkout | |
# the remaining $1 arg which is the branch name | |
# Else, (for example `co master` or `co master package.json`) pass all args to `git checkout` | |
if [[ $1 =~ [0-9]{4}-[0-9]{2}-[0-9]{2} && $2 =~ [0-9]{2}:[0-9]{2}:[0-9]{2} ]] | |
then shift; shift; shift | |
if [[ $1 == '*' ]]; then shift; fi | |
git checkout $1 | |
else | |
git checkout "$@" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment