Shortcuts for git (and other) commands - ganong-noel/lab_manual GitHub Wiki

Mac and Linux Users

One easy way to create shortcuts for common git commands is to use bash aliases. E.g., this way you can simply type gs rather than git status.

  1. Find and open .bash_profile as a text file

    • E.g., my .bash_profile is in Mac/Users/tcejka.
  2. Add the aliases that you want to create using the alias command:

    alias [shortcut] = '[command]'

  3. Save the .bash_profile.

  4. Restart your terminal/SSH session or type source ~/.bash_profile in the terminal for the change to take effect.

Example:

#[Aliases]
alias ga='git add'
alias gc='git commit'
alias gs='git status'
alias gb='git branch'
alias glast='git log -1'

You can also create aliases for other SSH commands, e.g.:

alias cdu='cd repo/uieip'
alias hist='history 20'

Windows Users

Method 1

  • If you are using Command Prompt (cmd.exe), then you can set up aliases using DOSKEY.
  • The simplest way to achieve this is as follows:
    1. Create a batch file, e.g., alias.bat.
    2. Write your aliases using the syntax from this example: doskey ga=git add.
    3. To use these shortcuts in a Command Prompt session, open your batch file by navigating to its directory and running: alias.bat.
  • These shortcuts will work only for the current session.

Method 2 (permanent and automatic shortcuts)

  • To create permanent aliases using DOSKEY and to make them available automatically when opening a Command Prompt session, see this link.
  • Unfortunately, this method is unavailable inside the Chase firewall.