284

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?

Peter Mortensen
  • 28,342
  • 21
  • 95
  • 123
iftheshoefritz
  • 4,465
  • 2
  • 29
  • 36
  • 1
    Read this for more recent versions : [https://stackoverflow.com/questions/32186840/git-for-windows-doesnt-execute-my-bashrc-file](https://stackoverflow.com/questions/32186840/git-for-windows-doesnt-execute-my-bashrc-file) – Victor Petit Mar 16 '18 at 14:35
  • For the WSL bash see this: https://stackoverflow.com/questions/40820822/location-of-bashrc-for-bash-on-ubuntu-on-windows-in-windows-10 – Vadzim Sep 28 '19 at 20:21

12 Answers12

342

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.

Peter Mortensen
  • 28,342
  • 21
  • 95
  • 123
Charles Ma
  • 41,485
  • 21
  • 80
  • 98
  • Where is the ~/.bashrc folder? – Andreas Lyngstad Nov 11 '11 at 21:02
  • 3
    It's a file, not a folder. ~/.bashrc is in your home directory, so it should be the directory you're in as soon as you start the git bash shell. just create a file called .bashrc and .gitconfig there. – Charles Ma Nov 11 '11 at 23:47
  • On my system ~ is pointing to c:\users\MyUser where MyUser is the currently logged in user – iftheshoefritz Dec 19 '11 at 13:23
  • How do you create a file called `.profile` or `.bashrc` in `~`? Everytime I try to do it in Explorer I get an error saying I must add a file name – David Sulpy Sep 17 '12 at 22:17
  • Ah, nevermind, I achieved this simply by echoing to a file called `~/.bashrc` – David Sulpy Sep 17 '12 at 22:18
  • Since a few people have asked about ~, I've edited the answer to clarify – Charles Ma Sep 17 '12 at 22:22
  • 12
    To create the .bashrc file you can execute the following from DOS prompt: copy > .bashrc. It creates the file with "The syntax of the command is incorrect." but you can edit it now. – tmorell May 26 '13 at 15:49
  • 34
    Just type `notepad ~/.bashrc` from the bash prompt and notepad will be launched with this file opened or will ask to create it, if it doesn't exist. If you're comfortable to vim, just type `vim ~/.bashrc`. It worked nicely to me. – Gerardo Lima Jul 10 '13 at 09:32
  • pwd in gitbash is also super useful for seeing the bash-ified windows path. In addition, where [util] is nice for seeing the windows path to utils. For example where git will tell you (in windows style) where git is. (which [util] will give you the bash path) – j03m Apr 24 '14 at 12:56
  • 11
    There are a trick in windows to create files like .profile (without letters before dot): right click -> create new file -> text file -> name it .profile. (NOTE THE DOT at the end) -> hit enter – Denis Apr 17 '15 at 09:01
  • 14
    You can also simply type `touch ~/.bashrc` – Chiel ten Brinke Oct 07 '15 at 07:56
  • Be sure to read the comment below from @harsel about .bash_profile. I needed to add the .bash_profile to my user directory `~/` on my Windows 10 Git Bash otherwise none of my alias' worked. – Jay Killeen Dec 08 '15 at 00:27
  • You can use Window Explorer to create a text file (be sure to include viewing extensions) and rename the file and file extension to `.bashrc.` – Kcvin Jan 31 '17 at 23:22
  • On Windows 10, the path to your home dir is usually `/c/Users/`, assuming the standard C drive letter. – GabeV Oct 31 '17 at 17:01
128

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.

Peter Mortensen
  • 28,342
  • 21
  • 95
  • 123
harsel
  • 1,615
  • 1
  • 11
  • 10
  • 6
    Thanks. This was exactly what was happening with my setup. – jmk2142 Sep 06 '15 at 21:06
  • Indeed, that's what happened to me recently after upgrade to 2.5. Thanks for your answer. – Vincent Sep 10 '15 at 03:17
  • 1
    Thanks from me too. it was driving me nuts that Git Bash was ignoring my .bashrc file, so your answer worked like a charm. – Mike Collins Feb 17 '16 at 17:25
  • "Just type notepad ~/.bashrc from the bash prompt and notepad will be launched with this file opened or will ask to create it, if it doesn't exist. If you're comfortable to vim, just type vim ~/.bashrc. It worked nicely to me. – Gerardo Lima" That solution work for me – fedeteka Apr 12 '19 at 20:25
  • Where should `.bash_profile` be created? Inside `~`? – theberzi Dec 08 '20 at 07:24
  • With 2.30.0.windows.1 git issues a WARNING and does this automatically for you. ``` WARNING: Found ~/.bashrc but no ~/.bash_profile, ~/.bash_login or ~/.profile. This looks like an incorrect setup. A ~/.bash_profile that loads ~/.bashrc will be created for you. ``` – BuddhiP Jan 30 '21 at 02:25
8

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.

Peter Mortensen
  • 28,342
  • 21
  • 95
  • 123
Stan S.
  • 539
  • 5
  • 13
  • add the user environment variable HOME and then create a .bashrc file with the required contents for example: #!/bin/bash export TERM=msys – snassr May 21 '15 at 14:31
7

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.
SiHa
  • 5,520
  • 12
  • 23
  • 37
Ruben Arevalo
  • 151
  • 2
  • 2
6

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.

Peter Mortensen
  • 28,342
  • 21
  • 95
  • 123
ThePatelGuy
  • 1,584
  • 1
  • 16
  • 17
  • This is a good alternative Windoze approach should someone wish to edit the file outside of git bash. Really helped me thanks. – haggisandchips Sep 27 '16 at 15:13
3

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.

Ayan
  • 5,592
  • 3
  • 30
  • 37
1

for gitbash in windows10 look out for the config file in

/.gitconfig file

Arun K
  • 87
  • 2
1

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

/etc/bash.bashrc
1

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

0

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.

Suraj Muraleedharan
  • 683
  • 1
  • 8
  • 21
-4

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

Peter Mortensen
  • 28,342
  • 21
  • 95
  • 123
Brandon
  • 353
  • 1
  • 4
  • 17
  • I'm not able to open the terminal anymore. While open the terminal it closed automatically. – maheshwaghmare Jun 21 '18 at 09:24
  • 1
    This solution doesn't help if an user doesn't have zsh in his/her machine. @maheshwaghmare If you still have an issue, remove three lines you added from .bashrc file. – YoungChoi Mar 22 '19 at 19:17
-7

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)
Peter Mortensen
  • 28,342
  • 21
  • 95
  • 123
s1w_
  • 134
  • 6