Git for Windows: .bashrc or equivalent configuration files for Git Bash shell
I've just installed Git for Windows and am delighted to see that it installs Bash.
I want to customise the shell in the same way I can under Linux (e.g. set up aliases like ll
for ls -l
), but I can't seem to find .bashrc
or equivalent configuration files.
What should I be editing?
Solution 1:
Create a .bashrc
file under ~/.bashrc
and away you go. Similarly for ~/.gitconfig
.
~
is usually your C:\Users\<your user name>
folder. Typing echo ~
in the Git Bash terminal will tell you what that folder is.
If you can't create the file (e.g. running Windows), run the below command:
copy > ~/.bashrc
The window will output an error message (command not found), but the file will be created and ready for you to edit.
Solution 2:
In newer versions of Git for Windows, Bash is started with --login
which causes Bash to not read .bashrc
directly. Instead it reads .bash_profile
.
If this file does not exist, create it with the following content:
if [ -f ~/.bashrc ]; then . ~/.bashrc; fi
This will cause Bash to read the .bashrc
file. From my understanding of this issue, Git for Windows should do this automatically. However, I just installed version 2.5.1, and it did not.
Solution 3:
I had to add a user environment variable, HOME
, with C:\Users\<your user name>
by going to System, Advanced System Settings, in the System Properties window, the Advanced tab, Environment Variables...
Then in my C:\Users\<your user name>
I created the file .bashrc
, e.g., touch .bashrc
and added the desired aliases.
Solution 4:
I think the question here is how to find .bashrc file on Windows.
Since you are using Windows, you can simply use commands like
start .
OR
explorer .
to open the window with the root directory of your Git Bash installation where you'll find the .bashrc
file. You may need to create one if it doesn't exist.
You can use Windows tools like Notepad++ to edit the file instead of using Vim in your Bash window.
Solution 5:
1) Start by opening up git-bash.exe in Administrator mode. (Right click the file and select "Run as Administrator", or change settings in Properties → Compatibility → Run this program as administrator.)
2) Run cd ~
. It will take you to C:/Users/<Your-Username>
.
3) Run vi .bashrc
. This will open you up into the editor. Hit INSERT and then start entering the following info:
alias ll="ls -la" # this changes the default ll on git bash to see hidden files.
cd "C:\directory\to\your\work\path\"
ll # this shows your your directory before you even type anything.