6

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.

Community
  • 1
  • 1
Zachrip
  • 3,242
  • 1
  • 17
  • 32

5 Answers5

7

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.

Boomer
  • 3,360
  • 20
  • 28
  • 2
    I'll try this, but the way I fixed it was using a .bash_profile instead. – Zachrip Aug 24 '15 at 16:00
  • 2
    Yes, same thing did the trick for me too. Apparently something was recently changed so only ~/.bash_profile is sourced, and not ~/.bashrc. – stian Oct 02 '15 at 08:14
5

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

Community
  • 1
  • 1
Expenzor
  • 432
  • 1
  • 5
  • 17
2

~/.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
StevenWernerCS
  • 839
  • 9
  • 15
  • Git for Windows (v2.37.1) does not create ~/.profile, nor does .profile exist in /etc/skel/.profile or /etc/defaults/etc/skel/.profile. It **does** read a .bashrc file in %USERPROFILE%. – cb4 Aug 02 '22 at 20:46
2

Default git-bash with mingw64 on Win10 seem to not source .bash_rc and .profile.

Use .bash_profile instead.

The original question (and the website via the link provided) talk about ssh-agent. It is a good idea to clean up the agent on git-bash exit via echo 'kill -KILL $SSH_AGENT_PID' >> .bash_logout. git-bash seems to keep those agents running across sessions but one can not access them anymore because the variables are already gone. .bash_logout is sourced in git-bash

Tested on Win10 machine $git version gives git version 2.20.1.windows.1

0

First, make sure to use the latest Git:

  • uncompressed PortableGit-2.5.0-64-bit.7z.exe anywhere you want, and add C:\path\to\PortableGit-2.5.0-64-bit\bin to your %PATH%.
  • then update your %USERPROFILE%\.bashrc
  • finally, launch C:\path\to\PortableGit-2.5.0-64-bit\git-bash.exe

If you are already in a bash session when modifyong the .bashrc, source it again to see if it does execute what you need.

source .bashrc
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250