Skip to content

Instantly share code, notes, and snippets.

@KyleMit
Last active June 13, 2019 17:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save KyleMit/69ec21465cfd14d93e6558b90ede223b to your computer and use it in GitHub Desktop.
Save KyleMit/69ec21465cfd14d93e6558b90ede223b to your computer and use it in GitHub Desktop.
Git Pair Alias

Git Pair Alias

Pair Programming is great - here's a way to make it greater with easy way to toggle on mutliple attribution for each a commit.

Add this alias to your global .gitconfig file (git config --global --edit)

[alias]
    pair = "!f() {                                                           \
                local name=$1;                                               \
                shopt -s nocasematch;                                        \
                case $name in                                                \
                    'John')                                                  \
                        git config user.name 'John and Kyle';                \
                        git config user.email John.Doe@domain.com;           \
                        ;;                                                   \
                    'James')                                                 \
                        git config user.name 'James and Kyle';               \
                        git config user.email James.Bond@domain.com;         \
                        ;;                                                   \
                    'Reset')                                                 \
                        git config user.name 'Kyle XY';                      \
                        git config user.email Kyle.XY@domain.com;            \
                        ;;                                                   \
                    *)                                                       \
                    ;;                                                       \
                    esac;                                                    \
                    echo 'Co-authored-by: Kyle XY <kyle.XY@domain.com>' | clip.exe; \
            }; f"

Then you can use it like this:

git pair John

Resources

How to Alias Command in Git

~/.gitconfig

[alias]
    co = checkout

OR

$ git config --global alias.co checkout 

Execute Bash Command inside of Git Alias

my_alias = "!f() { 〈your complex command〉 }; f"
  • $1 will access the first parameter
  • If you would like to wrap over multiple lines, each will need to be terminated with a \ as a line continuation character

Bash - Using Variables

name=Kyle
echo $name

Bash - Case Statement

case "$C" in
"1")
    do_this()
    ;;
"2" | "3")
    do_what_you_are_supposed_to_do()
    ;;
*)
    do_nothing()
    ;;
esac

Bash - Case Insensitive String Compare

str1="MATCH"
str2="match"
shopt -s nocasematch
case "$str1" in
   $str2 ) echo "match";;
   *) echo "no match";;
esac

Bash Copy variable to clipboard | Copy to Clipboard on windows

echo "bar" | xclip     # Linux
echo "foo" | pbcopy    # MacOS
echo "baz" | clip.exe  # Windows
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment