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?
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.
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 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.
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.
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.
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:
- Edit
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
- You may want set this file as executable inside Git Bash, chmod +x .bashrc (but it's probably redundant, since this file is stored on an NTFS filesystem)
来源:https://stackoverflow.com/questions/6883760/git-for-windows-bashrc-or-equivalent-configuration-files-for-git-bash-shell