DEV Community

Hafiz Jaafar
Hafiz Jaafar

Posted on

49 11 1 2 2

Git Bash on Windows: adding a permanent alias

If you are using Git Bash on Windows and you're used to Linux bash commands, chances are that you'd like to add aliases that help making your jobs easier.

These two are my favorite aliases:

$ alias cll='clear; ls -lah'
$ alias countFiles='ls -1 | wc -l'
Enter fullscreen mode Exit fullscreen mode

How to add an alias permanently for the Git Bash

  1. To add an alias permanently, you'd need to edit the file
    /C/Program Files/Git/etc/profile.d/aliases.sh .

  2. Run your text editor as an administrator and open that file.

  3. Add your alias and save the file.

  4. Open the Git Bash. Execute 'alias', and you're done. Have fun.

$ alias
alias cll='clear; ls -lah'
alias countFiles='ls -1 | wc -l'
alias ll='ls -lah'
alias ls='ls -F --color=auto --show-control-chars'
Enter fullscreen mode Exit fullscreen mode

Top comments (13)

Collapse
 
adeyemiadekore2 profile image
korey πŸ‡³πŸ‡¬ β€’ β€’ Edited

thanks for this.

a little thing to note is this works while navigating in bash

cd /c/'Program Files'/Git/etc/profile.d
not
cd /c/Program Files/Git/etc/profile.d as this one won't work in bash

Collapse
 
cornelius_figgle profile image
Max β€’

also to note: my git installation was in the AppData folder, so my path looked like this:

"%LocalAppData%\Programs\Git\etc\profile.d\aliases.sh"
OR
"C:\Users\<username>\AppData\Local\Programs\Git\etc\profile.d\aliases.sh"
OR
"~/AppData/Local/Programs/Git/etc/profile.d/aliases.sh"
OR
"/c/Users/<username>/AppData/Local/Programs/Git/etc/profile.d/aliases.sh"
Enter fullscreen mode Exit fullscreen mode
Collapse
 
natank profile image
natank β€’

Note: place the equal sign ('=') immediately after the alias without any spaces.
Examples:

alias k = 'kubectl' // not working
alias k= 'kubectl' // working

Collapse
 
prateek_aher profile image
Prateek Aher β€’

Dude, you're a lifesaver.

Collapse
 
binayashrestha profile image

thanks a lot.
also worked multi-line alias like this:

dcosql() {
  cd ~
  cd /d/dio/dio-scripts/docker/development/
  docker-compose up -d mssql
  }
Enter fullscreen mode Exit fullscreen mode
Collapse
 
flyingduck92 profile image
Sekti Wicaksono β€’

I always use ll with

alias ll='ls -lash'
Enter fullscreen mode Exit fullscreen mode
Collapse
 
cuneyter profile image
cuneyter β€’

Thank you. That is a great help :)

Collapse
 
chrisdev_io profile image
Christopher Thompson β€’

Great little bit of advice! Totally worked for me. Thank you. :D

Collapse
 
sddecent profile image
Decent Coder β€’

Aliases can be created using git config command as well, without actually opening the git files.

Collapse
 
rsbmk profile image
Roberto Bocio Melo β€’

thanks for this, my workflow thanks you ❀️

Sentry image

See why 4M developers consider Sentry, β€œnot bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

πŸ‘‹ Kindness is contagious

Please leave a ❀️ or a friendly comment on this post if you found it helpful!

Okay