Home > database >  Git bash in Windows: change the default directory when opening mintty (pwd)
Git bash in Windows: change the default directory when opening mintty (pwd)

Time:01-19

I am loosing a lot of time searching in internet for the following simple setting.

I installed git (and git bash) in Windows. What I want is just to open Git Bash and be in the directory I want. I don't want to change my home directory, just be in a given directory when I open the program.

More detailed, when I open Mingw / Git bash in Windows, I would like to be in the following folder:

/c/blabla/my_git_repositories

(this corresponds to the windows-style path: C:\blabla\my_git_repositories).

At the moment, I must write the following command every time I open GitBash:

cd /c/blabla/my_git_repositories

is this possible? Which file should i modify? Actually the program is installed here: C:\Program Files\Git\mingw64

Thanks

CodePudding user response:

If you want it happening every time you start an interactive shell, add

cd /c/blabla/my_git_repositories

to your shell startup. If your install includes the manpages say man bash and find the INVOCATION section, in a decent pager just /^INV will do it. Or Google knows to interpret a search for man bash as a search for the bash manpage.

Windows doesn't ordinarily support shell logins at all so a lot of the shell's startup-circumstance detection is overkill on Windows. Executing it is extremely fast, but describing exactly how it decides takes a page or two.

The short form is, if the startup was told it's a login shell it reads the login startup files, including (your) ~/.bash_profile, which generally should check for an interactive login and if so source the normal interactive shell startup ~/.bashrc, so ~/.bash_profile should end with something like

[[ $- = *i* && -f ~/.bashrc ]] && . ~/.bashrc

and put whatever you want in ~/.bashrc. That cd, set up your prompt colors, define your favorite shell aliases, add your personal scripts directory to PATH, whatever.

CodePudding user response:

Partial solution when opening the program by clicking on a link.

Right click on the link → properties → Start in: set the value to "C:\blabla\my_git_repositories".

This will work only when you open the application from that link, but could be fine (depending by your needs).

  • Related