0

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?

2
  • To some degree, the answer depends on which shell you use. Commented Mar 13, 2019 at 2:26
  • alias or ln in some bin folders Commented Mar 13, 2019 at 5:37

1 Answer 1

4

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.

Sign up to request clarification or add additional context in comments.

5 Comments

@njha I think Nikos comment is correct. It works in bash_profile but not in .profile.
.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.
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.
@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/…
There are a lot of shells other than bash.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.