Git for Windows: .bashrc or equivalent configuration files for Git Bash shell

WindowsGitGit Bash

Windows Problem Overview


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?

Windows Solutions


Solution 1 - Windows

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 - Windows

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 - Windows

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 - Windows

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 - Windows

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.

Solution 6 - Windows

  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.

Solution 7 - Windows

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.

Solution 8 - Windows

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.)

Solution 9 - Windows

Don't need to create a new file, it is already there!

/etc/bash.bashrc

Solution 10 - Windows

go to: C:\Program Files\Git\etc\profile.d inside you find all you need it

Solution 11 - Windows

for gitbash in windows10 look out for the config file in

/.gitconfig file

Solution 12 - Windows

On Windows:

you can find .bashrc in the directory: C:\Users\[YourUserName]

Solution 13 - Windows

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

Solution 14 - Windows

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)

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestioniftheshoefritzView Question on Stackoverflow
Solution 1 - WindowsCharles MaView Answer on Stackoverflow
Solution 2 - WindowsharselView Answer on Stackoverflow
Solution 3 - WindowsStan S.View Answer on Stackoverflow
Solution 4 - WindowsThePatelGuyView Answer on Stackoverflow
Solution 5 - WindowsAyanView Answer on Stackoverflow
Solution 6 - WindowsRuben ArevaloView Answer on Stackoverflow
Solution 7 - WindowsSuraj MuraleedharanView Answer on Stackoverflow
Solution 8 - WindowsDan MuellerView Answer on Stackoverflow
Solution 9 - WindowsSheldon OliveiraView Answer on Stackoverflow
Solution 10 - WindowsCarlos Andrés AlzateView Answer on Stackoverflow
Solution 11 - WindowsArun KView Answer on Stackoverflow
Solution 12 - WindowsMansour TorabiView Answer on Stackoverflow
Solution 13 - WindowsBrandonView Answer on Stackoverflow
Solution 14 - Windowss1w_View Answer on Stackoverflow