How to set aliases in the Git Bash for Windows?
GitBashGit Problem Overview
How to alias command in Git Bash for Windows downloaded from git-scm.com ?
I mean Bash commands not Git.
(windows7)
Edit:
Writing aliases in .bashrc
file (as suggested by @gturri) not adding it in console.(after system reboot)(I have never wrote alias for ls
command so it should be some default alias.)
Git Solutions
Solution 1 - Git
To configure bash aliases, it's the same as if you were on a Unix platform: put them in a .bashrc
in your home:
cd
echo alias ll=\'ls -l\' >> .bashrc
To have this change taken into account you should then either source this file (ie: run source .bashrc
) or restart your terminal
(In some cases* you can find equivalent for .bashrc
file in C:\Users\<username>\AppData\Local\GitHub\PortableGit_\etc\profile.d\aliases.sh.
And you should add aliases in aliases.sh.
)
(*this case is when you install Git for Windows GUI release from https://git-scm.com/download/win that contains GitBash)
Solution 2 - Git
I had the same problem, I can't figured out how to find the aliases used by Git Bash on Windows.
After searching for a while, I found the aliases.sh file under C:\Program Files\Git\etc\profile.d\aliases.sh
.
This is the path under windows 7, maybe can be different in other installation.
Just open it with your preferred editor in admin mode. After save it, reload your command prompt.
I hope this can help!
Solution 3 - Git
Follow below steps:
-
Open the file
.bashrc
which is found in locationC:\Users\USERNAME\.bashrc
If file
.bashrc
not exist then create it using below steps:- Open Command Prompt and goto
C:\Users\USERNAME\
. - Type command
notepad ~/.bashrc
It generates the.bashrc
file.
- Open Command Prompt and goto
-
Add below sample commands of WP CLI, Git, Grunt & PHPCS etc.
# ----------------------
# Git Command Aliases
# ----------------------
alias ga='git add'
alias gaa='git add .'
alias gaaa='git add --all'
# ----------------------
# WP CLI
# ----------------------
alias wpthl='wp theme list'
alias wppll='wp plugin list'
Now you can use the commands:
ga
instead ofgit add .
wpthl
instead ofwp theme list
Eg. I have used wpthl
for the WP CLI command wp theme list
.
Yum@M MINGW64 /c/xampp/htdocs/dev.test
$ wpthl
+------------------------+----------+-----------+----------+
| name | status | update | version |
+------------------------+----------+-----------+----------+
| twentyeleven | inactive | none | 2.8 |
| twentyfifteen | inactive | none | 2.0 |
| twentyfourteen | inactive | none | 2.2 |
| twentyseventeen | inactive | available | 1.6 |
| twentysixteen | inactive | none | 1.5 |
| twentyten | inactive | none | 2.5 |
| twentythirteen | inactive | none | 2.4 |
| twentytwelve | inactive | none | 2.5 |
For more details read the article Keyboard shortcut/aliases for the WP CLI, Git, Grunt & PHPCS commands for windows
Solution 4 - Git
You can add it manually in the .gitconfig file
[alias]
cm = "commit -m"
Or using the script:
git config --global alias.cm "commit -m"
Here is a screenshot of the .gitconfig
Solution 5 - Git
To Add a Temporary Alias:
- Goto Terminal (I'm using git bash for windows).
- Type
$ alias gpuom='git push origin master'
- To See a List of All the aliases type
$ alias
hit Enter.
To Add a Permanent Alias:
- Goto Terminal (I'm using git bash for windows).
- Type
$ vim ~/.bashrc
and hit Enter (I'm guessing you are familiar with vim). - Add your new aliases (For reference look at the snippet below).
#My custom aliases alias gpuom='git push origin master' alias gplom='git pull origin master'
- Save and Exit (Press Esc then type :wq).
- To See a List of All the aliases type
$ alias
hit Enter.
Solution 6 - Git
There is two easy way to set the alias.
- Using Bash
- Updating .gitconfig file
Using Bash
Open bash terminal and type git command. For instance:
$ git config --global alias.a add
$ git config --global alias.aa 'add .'
$ git config --global alias.cm 'commit -m'
$ git config --global alias.s status
---
---
It will eventually add those aliases on .gitconfig file.
Updating .gitconfig file
Open .gitconfig file located at 'C:\Users\username\.gitconfig' in Windows environment. Then add following lines:
[alias]
a = add
aa = add .
cm = commit -m
gau = add --update
au = add --update
b = branch
---
---
Solution 7 - Git
-
Go to
C:\Program Files\Git\etc\profile.d
-
Open as aliases.sh with your text editor as Administrator.
-
Add your new aliases and save
-
Restart git bash
Source: https://dev.to/mhjaafar/git-bash-on-windows-adding-a-permanent-alias-198g
Solution 8 - Git
-
Go to:
C:\Users\ [youruserdirectory] \bash_profile
-
In your bash_profile file type - alias desk='cd " [DIRECTORY LOCATION] "'
-
Refresh your User directory where the bash_profile file exists then reopen your CMD or Git Bash window
Type in desk to see if you get to the Desktop location or the location you want in the "DIRECTORY LOCATION" area above
Note: [ desk ] can be what ever name that you choose and should get you to the location you want to get to when typed in the CMD window.
Solution 9 - Git
Using Windows and MINGW64 GitBash (mintty 3.2.0), I found the file under:
%LocalAppData%\Programs\Git\etc\profile.d\aliases.sh
Just added the alias there and it worked for me.
Solution 10 - Git
I would prefer a zero-setup solution, but i found none yet. Once i Pull a repository, how can automagically have some standard alias available, so Bash shell for Git Extension can recognize it ? It seem that the C:\User<youruser>.bashrd is recognized, and also C:\Program Files\Git\etc\profile.d\aliases.sh, but these locations are outside the pulled project, and need to be manually configured.
Do exist some way to "autoconfigure" aliases for bash shell (for windows git extensions) just dropping a file in the project root, and not somewhere into user settings ?