DEV Community

Cover image for Created Git Shortcut Commands in .bashrc
Kenta Takeuchi
Kenta Takeuchi

Posted on • Originally published at bmf-tech.com

Created Git Shortcut Commands in .bashrc

This article was originally published on bmf-tech.com.

git add hogehoge, git commit hogehoge, git push hogehoge....

I only use basic git commands, but typing them 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
Enter fullscreen mode Exit fullscreen mode

Command Descriptions

  • git-b ・・・Check branches
  • git-c ・・・Checkout
  • git-c-b ・・・Create and checkout a new branch
  • git-p ・・・Pull
  • git-set ・・・Interactively perform add/commit/push. Please correct me as my English sounds awkward.

Troubleshooting

Thoughts

  • Development efficiency has slightly improved!
  • How do people who use git usually do it? Do they create aliases?

Addendum

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

Top comments (0)