Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

git-bash doesn't start in home folder on windows #794

Closed
ausminternet opened this issue Jun 21, 2016 · 28 comments
Closed

git-bash doesn't start in home folder on windows #794

ausminternet opened this issue Jun 21, 2016 · 28 comments
Labels

Comments

@ausminternet
Copy link

Hi there,

I'm using git for windows, version 2.9.0 in 64-bit. I'm not really sure, but in my memories the git-bash opened in the users home folder some time ago (c/users/username on windows 7).

The current version (and the last few versions, too) are opening the git-bash in root (/) and not in my user-folder.

Is this a bug, a feature, or are my memories wrong?

If my memories are wrong:

Configuring the .bash_profile to go to the home folder when it opens up breaks the "open git bash here" option, so is there a way to configure the git-bash to open up in home folders and not breaking the "open git bash here" option?

Greets, Jan

@PhilipOakley
Copy link

Try using pwd -W to find out what the true Windows path is to the putative current directory (of 'root')

there is a different file system philosophy between Windows and *nix. Windows has drives (plural) while *nix has root (singular).

So on G4W, a locally particular folder is chosen as the root directory, which depends on which bash exe you run. The SDK's bash and the program files bash can have different roots!

@ausminternet
Copy link
Author

user@host MINGW64 /
$ pwd -W
C:/Program Files/Git

@dscho
Copy link
Member

dscho commented Jun 21, 2016

git-bash opened in the users home folder some time ago

That is quite some time ago: 59d5f43

If you want it to open in the home directory, call it with --cd-to-home.

@dscho dscho closed this as completed Jun 21, 2016
@dscho dscho added the question label Jun 21, 2016
@ausminternet
Copy link
Author

At least, my memories were right :)

Thx, that worked.

@PhilipOakley
Copy link

On my little netbook (XP!), I see (it's not on-net at the moment), with the two different bashes,
G4W recent:
Title bar: MINGW32:/c/Documents and Setting/Philip
Philip@po MINGW32 ~
$ git version
git version 2.8.4.windows.1

Philip@po MINGW32 ~
$ pwd -W
C:/Documents and Settings/Philip

Philip@po MINGW32 ~
$ cd /
(Title bar changed to: MINGW32:/)
Philip@po MINGW32 /
$ pwd -W
C:/Program Files/Git


SDK recent:
Title bar: /
Philip@po MINGW32 /
$ git version
git version 2.8.4.windows.1.3.ge328a54

Philip@po MINGW32 /
$ pwd -W
C:/git-sdk-32

Philip@po MINGW32 /
$ cd /

Philip@po MINGW32 /
$ pwd -W
C:/git-sdk-32


note the two different root directories!
Also note the different title bar prefixes
(maybe the SDK should say 'SDK' ;-)

@dscho
Copy link
Member

dscho commented Jun 21, 2016

At least, my memories were right :)

@ausminternet yep, but there was no official Git for Windows version with that behavior. In other words: it was fixed before the first official release of Git for Windows 2.x.

SDK recent:
Title bar: /

@PhilipOakley Have you called pacman -Syu recently? I get SDK-64:/c/WINDOWS/system32 with my SDK, consistent with this part of /etc/profile.d/git-prompt.sh (which is owned by the git-extra package, my current version being 1.1.113.24fa039-1):

if test -f /etc/profile.d/git-sdk.sh
then
        TITLEPREFIX=SDK-${MSYSTEM#MINGW}
else
        TITLEPREFIX=$MSYSTEM
fi

@PhilipOakley
Copy link

@dscho I completely reloaded the SDK on the 7th June. (A previous attempt a couple of months ago at pacman -Syu had gone bad).

I moved/renamed my personal /git dir so I could bring it back without having lots of config hassles, deleted the old SDK and rebuilt afresh. Then put back my /git and made sure it was up to date.

When I install, I normally use the bash only install option. (and it's XP 32 bit ;-)

I had noticed that the PS prompt wasn't the same as the regular program files bash window, but too many other life issues to search it down.

@PhilipOakley
Copy link

@dscho, Was going to ask the dumb question: how do you get the git-extra package version? but Google saved me before I hit 'comment'.

pacman -Qe
...
git-extra 1.1.113.24fa039-1
..

meanwhile you said

my current version being 1.1.113.24fa039-1

so it looks as if it's up to date.

@dscho
Copy link
Member

dscho commented Jun 22, 2016

I had noticed that the PS prompt wasn't the same as the regular program files bash window

So you see the SDK-32 prefix in SDK's git-bash now?

@PhilipOakley
Copy link

From: Johannes Schindelin

I had noticed that the PS prompt wasn't the same as the regular program
files bash window
So you see the SDK-32 prefix in SDK's git-bash now?

Unfortunately no. Even after a restart.

The titlebar is still just "/" at startup of the bash, with a prompt of

Philip@PhilipOakley MINGW32 /
$

(colouring is approx green, purple, orange, with my colour settings)

Philip

@dscho
Copy link
Member

dscho commented Jun 22, 2016

Unfortunately no. Even after a restart.

Can you verify that /etc/profile.d/git-prompt.sh contains the lines I mentioned earlier?

@PhilipOakley
Copy link

Hi @dscho ,
yes, the lines are there, and the git-sdk.sh is present in the sdk directory (and not in the program files directory).

I'm at a bit of a loss in how to debug this (*nix start up) stuff, e.g. determining which actual scripts are being sourced.

side thoughts:
Is the TITLEPREFIX code meant to work in the 32bit XP?

Does/should the git-prompt.sh need a shebang line?

Did manage to add an 'echo xxx' at L#8 of the git-prompt scripts and can see they are both executing at startup.

@PhilipOakley
Copy link

@dscho I think this http://superuser.com/a/886247/596154 (competing title settings set in other PS1 settings) may have some useful insights. I don't have enough time at the moment to pursue it much further, but maybe later.

I may trigger an 'Aha' moment for you.

@dscho
Copy link
Member

dscho commented Jun 22, 2016

Is the TITLEPREFIX code meant to work in the 32bit XP?

Yes.

(competing title settings set in other PS1 settings) may have some useful insights.

Maybe you set your PS1 in $HOME/.bash_profile?

I'm at a bit of a loss in how to debug this

I typically debug this by inserting a set -x into the startup files. This tells Bash that it should output a trace of commands that are executed from now on, and maybe something there rings a bell?

@PhilipOakley
Copy link

I've found c:\git-sdk-32\etc\bash.bashrc#L44-46 would appear to have the PS1 line that's showing up in my SDK window. It appears to be conditional on MSYS2_PS1 existing . I'll try and play with that.

I'll try the -x trick now you've prompted me.

After posting I realised that TITLEPRFIX must be working, 'cos the other (progam file/git) window was working - sometimes one can't see the blindingly obvious...

@PhilipOakley
Copy link

@dscho, I tweaked the c:\git-sdk-32\etc\bash.bashrc#L42-47 and can confirm that the displayed prompt (with the SDK bash) is the default one from there, while that piece of code is missing from the C:\Program Files\ version. (see the extra "Hi-" before the $MSYSTEM ;-)

# If MSYS2_PS1 is set, use that as default PS1, otherwise set a default prompt
# of user@host, MSYSTEM variable, and current_directory
if test -n "${MSYS2_PS1}"
    then PS1="${MSYS2_PS1}"
    else PS1='\[\e]0;\w\a\]\n\[\e[32m\]\u@\h \[\e[35m\]Hi-$MSYSTEM\[\e[0m\] \[\e[33m\]\w\[\e[0m\]\n\$ '
fi

I haven't started looking at how that file is 'created/fetched' during the SDK install yet, nor if we should simply define an extra MSYS2_PS1="$PS1" at the end of the C:\git-sdk-32\etc\profile.d\git-prompt.sh (perhaps as a workaround - looks like it works)

@PhilipOakley
Copy link

I've just done a fresh full install of the SDK, and of Git 2.9.0, on my wife's W7 home office PC, and it has exactly the same issue.

The c:\git-sdk-**XX**\etc\bash.bashrc#L42-47 is causing the PS1 from git-prompt.sh to be overwritten.

How do I determine which package it was that loaded the c:\git-sdk-**XX**\etc\bash.bashrc file ?

I'm thinking it was one of the many pacman installs.

@dscho
Copy link
Member

dscho commented Jun 24, 2016

How do I determine which package it was that loaded the c:\git-sdk-XX\etc\bash.bashrc file ?

You mean "installed" by "loaded"? If so, it is pacman's -Qo option. Mine says:

$ pacman -Qo /etc/bash.bashrc
/etc/bash.bashrc is owned by filesystem 2016.05-3

@PhilipOakley
Copy link

Thanks, sorry about the jotd (jargon of the day ;-) misunderstanding .

I did eventually find that invocation, and the follow up -Qi to get

Philip@PhilipOakley MINGW32 /
$ pwd -W
C:/git-sdk-32

Philip@PhilipOakley MINGW32 /
$ pacman -Qo etc/bash.bashrc
/etc/bash.bashrc is owned by filesystem 2016.05-2

Philip@PhilipOakley MINGW32 /
$ pacman -Qi filesystem
Name            : filesystem
Version         : 2016.05-2
Description     : Base filesystem
Architecture    : i686
URL             : https://sourceforge.net/projects/msys2/
Licenses        : BSD
Groups          : base
Provides        : msys2-base
Depends On      : None
Optional Deps   : None
Required By     : dash
Optional For    : git-extra
Conflicts With  : None
Replaces        : msys2-base
Installed Size  : 88.00 KiB
Packager        : Alexey Pavlov <alexpux@gmail.com>
Build Date      : Fri, May 27, 2016 9:21:49 AM
Install Date    : Sun, Jun 12, 2016 2:32:18 PM
Install Reason  : Explicitly installed
Install Script  : Yes
Validated By    : Signature

Philip@PhilipOakley MINGW32 /
$ pacman -Qo /c/Program\ Files/Git/etc/bash.bashrc
error: No package owns /c/Program Files/Git/etc/bash.bashrc

I've then had a look at the what I believe is the msys2-base package at msys2-base-i686-20160205.tar.xz at https://sourceforge.net/projects/msys2/files/Base/i686/ and see that compared to the file in that tar, at the end of the full SDK the file has been updated/overwritten.

So I'm still unsure which package or patch owns that particular version of the file. Any pointers on how to detect, during the install, if the file has been updated?

PS: should this be moved/copied to a fresh issue?

@dscho
Copy link
Member

dscho commented Jun 29, 2016

PS: should this be moved/copied to a fresh issue?

Usually I prefer this. With active and responsive contributors, I am of course trying to accommodate ;-)

@landstander668
Copy link

Not a fix, but adding this snippit to ~/.bash_profile seems to reliably work around the issue for me without the side effect of breaking Git Bash Here. I'm using tje 2.9.0 64-bit installer release on Windows 7.

if [ "$PWD" = "/" ]; then
   cd
fi

This approach breaks down, of course, if you actually want to begin in the root directory. That's been exceedingly rare in my case, however.

@dscho
Copy link
Member

dscho commented Jun 29, 2016

If you want it to open in the home directory, call it with --cd-to-home.

I still think this is the correct solution.

FWIW my Git for Windows v2.9.0 64-bit's Git Bash opens in the home directory, as it should. The shortcut installed into the start menu uses that --cd-to-home option.

@landstander668
Copy link

The shortcut does indeed include the --cd-to-home option. As far as I can tell this is only an issue when invoking git-bash.exe directly, with the parameter omitted... double-clicking it from the file explorer, for example. I'd agree that launching it with the parameter is the most correct solution.

Personally, I like to assign a key sequence to the shortcut in cases like this. In my case Ctrl-Alt-G invokes the program menu shortcut from anywhere, with the relevant parameter included.

@fourpastmidnight
Copy link

Same here, my git-bash defaults to home dir because of the --cd-to-home flag in the shortcut installed by the installer--since, well, for as long as I can remember--which is about at least the last two or three years.

@fourpastmidnight
Copy link

@landstander668 That's exactly right! 😄

PhilipOakley pushed a commit to PhilipOakley/MSYS2-packages that referenced this issue Jul 5, 2016
6e6310d (filesystem: New specific variable MSYS2_PS1., 2016-05-01)
introduced the MSYS2_PS1 prompt script proriority to allow multiple
device configurations.

Unfortunately it overwrote the $PS1, even when specifically set by the
users configuration, such as the Git-for-Windows SDK
see git-for-windows/git#794 (comment)
and the monkey patch fix
git-for-windows/build-extra#122.

Introduce a priority order so that the user's $PS1 (if set) has an
intermediate priority between the MSYS2_PS1 and the default PS1.

Signed-off-by: Philip Oakley <philipoakley@iee.org>
PhilipOakley pushed a commit to PhilipOakley/MSYS2-packages that referenced this issue Jul 5, 2016
6e6310d (filesystem: New specific variable MSYS2_PS1., 2016-05-01)
introduced the MSYS2_PS1 prompt script proriority to allow multiple
device configurations.

Unfortunately it overwrote the $PS1, even when specifically set by the
users configuration, such as the Git-for-Windows SDK
see git-for-windows/git#794 (comment)
and the monkey patch fix
git-for-windows/build-extra#122.

Introduce a priority order so that the user's $PS1 (if set) has an
intermediate priority between the MSYS2_PS1 and the default PS1.

Signed-off-by: Philip Oakley <philipoakley@iee.org>
PhilipOakley pushed a commit to PhilipOakley/MSYS2-packages that referenced this issue Jul 6, 2016
6e6310d (filesystem: New specific variable MSYS2_PS1., 2016-05-01)
introduced the MSYS2_PS1 prompt script priority to allow multiple
device configurations.

Unfortunately, if MSYS2_PS1 was not set it overwrote the $PS1, even
when specifically set by the users configuration, such as provided in the
Git-for-Windows SDK (see git-for-windows/git#794 (comment))
and the monkey patch fix (git-for-windows/build-extra#122).

Introduce a priority order so that the user's $PS1 (if set) has an
intermediate priority between the MSYS2_PS1 and the default PS1.

Signed-off-by: Philip Oakley <philipoakley@iee.org>
@mgedmin
Copy link

mgedmin commented Aug 30, 2016

FWIW I had this problem too, because of user error:

  • install Git for Windows (latest version as of yesterday; git --version reports 2.9.3.windows.2)
  • run Git Bash
  • right-click the icon in the task bar and select "Pin this program to taskbar"
  • close Git Bash
  • click the taskbar icon to launch Git Bash --> starts in / instead of ~

The right way to pin it to the taskbar is to right-click the desktop icon and select "Pin to Taskbar" there.

@PhilipOakley
Copy link

Marius,

you have two 'taskbar's in there (step 3 and step 5). It may need a little extra clarification between the pinned and unpinned icons within the "taskbar".

Philip
----- Original Message -----
From: Marius Gedminas
To: git-for-windows/git
Cc: Philip Oakley ; Mention
Sent: Tuesday, August 30, 2016 7:59 AM
Subject: Re: [git-for-windows/git] git-bash doesn't start in home folder on windows (#794)

FWIW I had this problem too, because of user error:

a.. install Git for Windows (latest version as of yesterday; git --version reports 2.9.3.windows.2) 
b.. run Git Bash 
c.. right-click the icon in the task bar and select "Pin this program to taskbar" 
d.. close Git Bash 
e.. click the taskbar icon to launch Git Bash --> starts in / instead of ~ 

The right way to pin it to the taskbar is to right-click the desktop icon and select "Pin to Taskbar" there.


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub, or mute the thread.

@raddevus
Copy link

raddevus commented Feb 7, 2021

FWIW I had this problem too, because of user error:

  • install Git for Windows (latest version as of yesterday; git --version reports 2.9.3.windows.2)
  • run Git Bash
  • right-click the icon in the task bar and select "Pin this program to taskbar"
  • close Git Bash
  • click the taskbar icon to launch Git Bash --> starts in / instead of ~

The right way to pin it to the taskbar is to right-click the desktop icon and select "Pin to Taskbar" there.

Ran into this exact problem after installing v2.30.0 of GitBash on Win10.
You can also right-click the Git bash icon that is in your Start menu and pin it to the task bar.
The one that doesn't work (doesn't set you to your user home) is when you right-click the running copy of gitbash and say pin to taskbar.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

7 participants