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?
Don't need to create a new file, it is already there!
/etc/bash.bashrc
Sometimes the files are actually located at ~/
. These are the steps I took to starting Zsh as the default terminal on Visual Studio Code/Windows 10.
cd ~/
vim .bashrc
Paste the following...
if test -t 1; then
exec zsh
fi
Save/close Vim.
Restart the terminal
If you want to have projects choice list when you open Git Bash:
ppath
in the code header to your Git projects path, put this code into .bashrc file, and copy it into your $HOME directory (in Windows Vista / Windows 7 it is often C:\Users\$YOU).
#!/bin/bash
ppath="/d/-projects/-github"
cd $ppath
unset PROJECTS
PROJECTS+=(".")
i=0
echo
echo -e "projects:\n-------------"
for f in *
do
if [ -d "$f" ]
then
PROJECTS+=("$f")
echo -e $((++i)) "- \e[1m$f\e[0m"
fi
done
if [ ${#PROJECTS[@]} -gt 1 ]
then
echo -ne "\nchoose project: "
read proj
case "$proj" in
[0-`expr ${#PROJECTS[@]} - 1`]) cd "${PROJECTS[proj]}" ;;
*) echo " wrong choice" ;;
esac
else
echo "there is no projects"
fi
unset PROJECTS
Please use the following command,
cat /etc/bash.bashrc > ~/.bashrc
This will generate a new bashrc file with the default values. Please use vi ~/.bashrc
to edit this file.
In your home directory, you should edit .bash_profile if you have Git for Windows 2.21.0 or later (as of this writing).
You could direct .bash_profile to just source .bashrc, but if something happens to your .bash_profile, then it will be unclear why your .bashrc is again not working.
I put all my aliases and other environment stuff in .bash_profile, and I also added this line:
echo "Sourcing ~/.bash_profile - this version of Git Bash doesn't use .bashrc"
And THEN, in .bashrc I have
echo "This version of Git Bash doesn't use .bashrc. Use .bash_profile instead"
(Building on @harsel's response. I woulda commented, but I have no points yet.)
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.
Just notepad ~/.bashrc
from the git bash shell and save your file.That should be all.
NOTE: Please ensure that you need to restart your terminal for changes to be reflected.
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.
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.
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.
for gitbash in windows10 look out for the config file in
/.gitconfig file
Source: Stackoverflow.com