2

I would like to rename the following git commands:

Instead of typing:

  • git checkout I would like to rename it to git co.

  • git commit I would like to rename it to git cm.

  • git push origin I would like to rename it to git po.

How can I do this?

Thanks!

Lizz Parody
  • 1,705
  • 11
  • 29
  • 48
  • https://git-scm.com/book/en/v2/Git-Basics-Git-Aliases – choroba May 14 '18 at 14:12
  • 2
    Possible duplicate of [How do I alias commands in git?](https://stackoverflow.com/questions/2553786/how-do-i-alias-commands-in-git) – phd May 14 '18 at 15:15

3 Answers3

3

The chapter "Git Aliases" in the Pro Git book shows exactly what you need:

git config --global alias.co checkout
git config --global alias.cm commit
git config --global alias.po 'push origin'
choroba
  • 231,213
  • 25
  • 204
  • 289
1

What you want to do is creating so called 'aliases' for your $shell (bash/csh/zsh/fish).

Try this excellent blog post from well known david walsh: https://davidwalsh.name/alias-bash

But be careful: non-standard aliases will break your mind when working on a remote machine via ssh or when switching machines, and if you use your aliases in scripts they won't run elsewhere!

lolops
  • 97
  • 1
  • 11
1

Use aliases : here is a link showing how does it work.

You can put something like this in your .bash_profile file:

alias checkout='git checkout'
alias pull='git pull'
alias push='git push origin'
alias push_f='git push origin -f'
alias rebase='git rebase'
#...

and then source .bash_profile

Now you can write : checkout master, push master, checkout master

Be carefull: you cannot put arguments when you declare aliases.

black4bird
  • 617
  • 1
  • 5
  • 13