When I am in the terminal, if is there a way to set shortcuts for commands? For example, if I type "g" make it equal "git", and if I type "gs" make it equal "git status". etc?
1 Answer
You can use the bash alias command.
Edit your ~/.bash_profile file (for Mac) and add the following to the end.
alias g="git"
alias gs="git status"
Changes will take any effect for any new terminals, but not ones that are already open.
5 Comments
SilentDev
@njha I think Nikos comment is correct. It works in bash_profile but not in .profile.
Nikos C.
.bash_profile will override .profile. Also, it's not sourced for sh, only for bash, which makes it a good idea to put aliases in .bash_profile instead of .profile since you don't want aliases to interfere with scripts that use #!/bin/sh.33-B01
It should be noted that changes to
~/.bash_profile will only take effect in new terminal windows. In other words, windows that were opened before the modification won't see those aliases.Jamin Kortegard
@focorner that's true. You can manually reload the profile in the current terminal session with
source ~/.bash_profile, as detailed in the answer stackoverflow.com/questions/4608187/…Caleb
There are a lot of shells other than bash.