/git-aliases

πŸ”₯ Streamline Git Operations with Time-Saving Aliases.

Git Aliases

πŸ”₯ Streamline Git Operations with Time-Saving Aliases.

Contributions open

Git aliases

English | EspaΓ±ol

πŸ“œ Table of contents

✳ Create a global alias using Git Bash

  1. Open a Git Bash terminal and make sure you're in your user's location using the following command:

    cd ~
  2. Run the following command to create or configure your profile:

    notepad .bash_profile

    If you haven't created this file yet, you'll be prompted to create a new one; confirm and proceed.

  3. Inside the .bash_profile file, you can add your first alias. For example:

    alias g='git'

    When you save the changes, this will set a global alias "g" for the "git" command.

  4. Now you can use this alias in any Git project on your system. For example, instead of typing git -v, simply type:

    g -v
  5. If you forget any of your aliases, you can view the complete list by running the following command:

    alias

Note: These steps are not applicable to terminals like CMD or PowerShell since the configurations are specific to Git Bash and won't reflect in other terminals. Each terminal environment has its independent configurations.

✨ Recommended configurations (by Midudev)

Alias for the git command:
  • βš™οΈ Configuration:

    alias g='git'
  • πŸš€ Usage:

    g
    
Add all changes to the staging area:
  • βš™οΈ Configuration:

    alias gaa='git add -A'
  • πŸš€ Usage:

    gaa
    
Show the current repository status:
  • βš™οΈ Configuration:

    alias gst='git status'
  • πŸš€ Usage:

    gst
    
Perform a pull operation from the remote repository:
  • βš™οΈ Configuration:

    alias gl='git pull'
  • πŸš€ Usage:

    gl
    
Update the local repository using fetch and rebase:
  • βš™οΈ Configuration:

    alias gup='git fetch && git rebase'
  • πŸš€ Usage:

    gup
    
Push changes to the remote repository:
  • βš™οΈ Configuration:

    alias gp='git push'
  • πŸš€ Usage:

    gp
    
Show differences with enhanced formatting:

The following alias requires diff-so-fancy:

  • βš™οΈ Configuration:

    gd() { git diff -w "$@" | diff-so-fancy - }
  • πŸš€ Usage:

    gd
    
Commit with a message:
  • βš™οΈ Configuration:

    alias gc='git commit -m'
  • πŸš€ Usage:

    gc "Commit message"
    
Commit with a message and additional changes:
  • βš™οΈ Configuration:

    alias gca='git commit -v -a'
  • πŸš€ Usage:

    gca
    
Perform a checkout operation:
  • βš™οΈ Configuration:

    alias gco='git checkout'
  • πŸš€ Usage:

    gco <branch_name_or_commit>
    
Switch to the "master" branch:
  • βš™οΈ Configuration:

    alias gcm='git checkout master'
  • πŸš€ Usage:

    gcm
    
List local branches:
  • βš™οΈ Configuration:

    alias gb='git branch'
  • πŸš€ Usage:

    gb
    
List all branches, including remote ones:
  • βš™οΈ Configuration:

    alias gba='git branch -a'
  • πŸš€ Usage:

    gba
    
Show commit count per author:
  • βš™οΈ Configuration:

    alias gcount='git shortlog -sn'
  • πŸš€ Usage:

    gcount
    
Cherry-pick a specific commit:
  • βš™οΈ Configuration:

    alias gcp='git cherry-pick'
  • πŸš€ Usage:

    gcp <commit_hash>
    
Show commit log with statistics:
  • βš™οΈ Configuration:

    alias glg='git log --stat --max-count=5'
  • πŸš€ Usage:

    glg
    
Show commit log as a graph:
  • βš™οΈ Configuration:

    alias glgg='git log --graph --max-count=5'
  • πŸš€ Usage:

    glgg
    
Show the current status in a summarized form:
  • βš™οΈ Configuration:

    alias gss='git status -s'
  • πŸš€ Usage:

    gss
    
Add changes to the staging area:
  • βš™οΈ Configuration:

    alias ga='git add'
  • πŸš€ Usage:

    ga <file_or_directory_name>
    
Perform a merge operation:
  • βš™οΈ Configuration:

    alias gm='git merge'
  • πŸš€ Usage:

    gm <branch_name_to_merge>
    
Undo changes in the staging area:
  • βš™οΈ Configuration:

    alias grh='git reset HEAD'
  • πŸš€ Usage:

    grh <file_or_directory_name>
    
Forcefully undo changes in the staging area:
  • βš™οΈ Configuration:

    alias grhh='git reset HEAD --hard'
  • πŸš€ Usage:

    grhh <file_or_directory_name>
    
Create a new branch and switch to it:
  • βš™οΈ Configuration:

    alias gcb="git switch -c \$1"
  • πŸš€ Usage:

    gcb <new_branch_name>
    

πŸ“š Add all recommended aliases

alias g='git'
alias gaa='git add -A'
alias gst='git status'
alias gl='git pull'
alias gup='git fetch && git rebase'
alias gp='git push'
alias gc='git commit -m'
alias gca='git commit -v -a'
alias gco='git checkout'
alias gcm='git checkout master'
alias gb='git branch'
alias gba='git branch -a'
alias gcount='git shortlog -sn'
alias gcp='git cherry-pick'
alias glg='git log --stat --max-count=5'
alias glgg='git log --graph --max-count=5'
alias gss='git status -s'
alias ga='git add'
alias gm='git merge'
alias grh='git reset HEAD'
alias grhh='git reset HEAD --hard'
alias gcb="git switch -c $1"

The following alias requires diff-so-fancy:

gd() { git diff -w "$@" | diff-so-fancy - }

🧩 Contributions

We invite you to share your aliases in a pull request.