Application 2017-09-26

Created Git Shortcut Commands in .bashrc

Create powerful git aliases and bash functions for branch checkout, pull, and push operations using .bashrc configuration.

Read in: ja
Created Git Shortcut Commands in .bashrc

git add foo, git commit foo, git push foo....

I only use basic git commands, but typing them out every time is cumbersome, so I decided to create some aliases.

Script

#git branch
alias git-b='git branch'

#git checkout
function gitCheckout() {
         stty erase ^H
         echo -n "What is the new branch name?" 
         stty echo
         read var1
         git checkout ${var1}
}
alias git-c=gitCheckout

#git checkout -b
function gitCheckoutBranch() {
         stty erase ^H
         echo -n "What is the new branch name for checkout?"
         stty echo
         read var1
         git checkout -b ${var1}
}
alias git-c-b=gitCheckoutBranch

#git pull
function gitPull() {
        stty erase ^H
        echo -n "What is the remote repository name?"
        stty echo
        read var1
        git pull origin ${var1}
}
alias git-p=gitPull

#git set
function gitSet() {
      stty erase ^H
      echo -n "What file name do you add?"
      read var1
      git add ${var1}
      echo -n "What is the commit message?"
      read var2
      git commit -m\'${var2}\'
      echo -n "What is the branch name?"
      stty echo
      read var3
      git push origin ${var3}
}
alias git-set=gitSet

Command Descriptions

Troubleshooting

Thoughts

Postscript

I forgot there is a command called git config for setting git aliases. Set aliases for commonly used git commands to improve development efficiency

Tags: bash Git shell script
Share: 𝕏 Post Facebook Hatena
✏️ View source / Discuss on GitHub
☕ Support

If you enjoy this blog, consider supporting it. Every bit helps keep it running!


Related Articles