- β³ Create a global alias using Git Bash
- β¨ Recommended configurations
- π Add all recommended aliases
- 𧩠Contributions
-
Open a Git Bash terminal and make sure you're in your user's location using the following command:
cd ~
-
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.
-
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.
-
Now you can use this alias in any Git project on your system. For example, instead of typing
git -v
, simply type:g -v
-
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>
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 - }
We invite you to share your aliases in a pull request.