Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

.bashrc not executed when starting GitBash

I'm following this guide, I've gotten to the part where I need to create the .bashrc file and it doesn't seem to execute when I restart GitBash. I've tried a few things including the answers on this SO question. I've also tried just having an echo in it for testing, which works when I execute it directly, but not when I start GitBash.

like image 345
Zachrip Avatar asked Aug 22 '15 04:08

Zachrip


People also ask

Does Git bash use bashrc?

In newer versions of Git for Windows, Bash is started with --login which causes Bash to not read . bashrc directly. Instead it reads .

Where do I put the .bashrc file?

In most cases, the bashrc is a hidden file that lives in your home directory, its path is ~/. bashrc or {USER}/. bashrc with {USER} being the login currently in use.


3 Answers

I solved the problem by executing git-bash -l -c bash (the -l is a lower-case L). With that my $HOME/.bashrc gets executed immediately.
I am using PortableGit 2.5.0 on Windows 7.

like image 156
Boomer Avatar answered Oct 01 '22 11:10

Boomer


As of Git 2.5.0 .bashrc no longer seems to be referenced to %USERPROFILE%\.bashrc.

But you can edit this file: "C:\Program Files\Git\etc\bash.bashrc". It's a global file but it will have to do.

Also I think it's recommended to edit the files located at "C:\Program Files\Git\etc\profile.d" instead of creating .bashrc.

The files inside that folder read like:

Some good standards, which are not used if the user

creates his/her own .bashrc/.bash_profile

like image 35
Expenzor Avatar answered Oct 01 '22 12:10

Expenzor


~/.bashrc is not sourced by default, but ~/.profile is...

you just create a ~/.profile that sources your ~/.bashrc

The below is the ~/.profile my cygwin came with that I copied to my into my git-bash's ~.

# To the extent possible under law, the author(s) have dedicated all
# copyright and related and neighboring rights to this software to the
# public domain worldwide. This software is distributed without any warranty.
# You should have received a copy of the CC0 Public Domain Dedication along
# with this software.
# If not, see <http://creativecommons.org/publicdomain/zero/1.0/>.

# base-files version 4.2-4

# ~/.profile: executed by the command interpreter for login shells.

# The latest version as installed by the Cygwin Setup program can
# always be found at /etc/defaults/etc/skel/.profile

# Modifying /etc/skel/.profile directly will prevent
# setup from updating it.

# The copy in your home directory (~/.profile) is yours, please
# feel free to customise it to create a shell
# environment to your liking.  If you feel a change
# would be benificial to all, please feel free to send
# a patch to the cygwin mailing list.

# User dependent .profile file

# Set user-defined locale
export LANG=$(locale -uU)

# This file is not read by bash(1) if ~/.bash_profile or ~/.bash_login
# exists.
#
# if running bash
if [ -n "${BASH_VERSION}" ]; then
  if [ -f "${HOME}/.bashrc" ]; then
    source "${HOME}/.bashrc"
  fi
fi
like image 40
StevenWernerCS Avatar answered Oct 01 '22 11:10

StevenWernerCS