Reputation: 4360
I am using Git on Windows 7 and access my repositories through Git Bash. How can I change the default location that Git Bash opens in a convenient folder when I start it?
It's somewhat time consuming to navigate to htdocs
, and then a specific folder. Is there a way to change the configuration file to have it open elsewhere? Or would it be possible to write a .sh
file to do this?
Unfortunately Git Bash won't open my htdocs
folder shortcut on my desktop, and it takes using cd
5 times to get to my desired directory.
Upvotes: 321
Views: 346293
Reputation: 7581
The easiest way without installing msysgit is right click on the Git Bash shortcut icon → Properties → Start in: → "C:\Program Files (x86)".
Change the Start in entry and point out the Git Bash starting position. If you don't remove the --cd-to-home
part from the Target box, the Start in change gets overridden.
Alternate Option:
If you don't have the shortcut and installed in the default location, open up a file explorer and paste in the search path field:
C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Git
That will take you to the Git shortcuts location
--cd-to-home
Good to go
Upvotes: 296
Reputation: 808
On Windows 11 if you pined gitbash to TaskBar then it loosing "--cd-to-home" flag. So it has to be added there manually again. It can be done via right click on the pinned icon and then again right click on gitbash icon. Then "properties".
Upvotes: 0
Reputation: 11
On Windows 11, create a file named .bashrc
in your user directory, like C:/user/.bashrc
, and add this single line to the file:
cd ~ [enter the full path of where you want git bash to start up]
.
It took a while, but I found out that ~
is the 'wildcard' option, so you could type something specific like cd ~/MyProject
and always start there.
Upvotes: 0
Reputation: 1
You can create a .bashrc configuration file:
cd ~ && touch .bashrc && echo "cd /folder1/folder2/folder3"
Change cd command to the directory you want.
Upvotes: 0
Reputation: 1443
As from this link
lets say you want your change to default location to c:\myprojects
Open git bash
type in:
echo "cd 'C:\myprojects'" >> ~/.bash_profile
Press Enter
Close Git bash and open again
You should start from c:\myprojects
Tested on git version 2.36.1 on windows
Troubleshoot:
Upvotes: 1
Reputation: 1737
If using Windows OS then add target like above :
Upvotes: 9
Reputation: 41
Since I'm using git-bash inside of vscode as a terminal I don't always want to cd into a specific directory, for this to work I checked if my current directory(pwd
) is /
and if so it should only then cd to ~
. So whenever I open the terminal inside vscode git-bash's current working directory is my opened folder inside of vscode and it doesn't change to ~
since it only does that when my current working directory is /
.
For this to work I added following if condition into ~/.bashrc
:
if [ $(pwd) = '/' ] then cd ~; fi
TIP: make sure your ~/.bash_profile
actually loads ~/.bashrc
by a line like the following:
if [ -f ~/.bashrc ]; then . ~/.bashrc; fi
Upvotes: 0
Reputation: 2039
If you're using Git Bash through Windows Terminal, you can set the starting directory (of any profile).
In Windows Terminal, go to Settings
> Open JSON file
.
In this file, in profiles
> list
, you can set the startingDirectory
property (backslashes need to be escaped).
See the documentation.
Upvotes: 5
Reputation: 662
1/ Go to Properties of Git Bash
2/ Change Start in: to your the directory of your choi
3/ Delete --cd-to-home
4/ Restart Git Bash
Upvotes: 13
Reputation: 5663
Add a line to change to the desired directory in your .bashrc file or create a .bashrc if you don't have one.
I.e. add cd C:/path/to/yourfolder
to your .bashrc file
Be mindful that the path format is forward slash '/' Unix style and not Windows '\' backslash.
One way to do this is to open bash and edit it using vim
I found this solution on https://simplernerd.com/cli-git-bash-default/
Upvotes: 3
Reputation: 271
Open this file:
C:\Program Files\Git\etc\bash.bashrc
And append the following line:
cd /c/Users/<User>/Documents/path/to/your/repos
Restart Git bash
Upvotes: 6
Reputation: 1149
the only way that worked for me on windows 10:
This will always open desktop path
Upvotes: 3
Reputation: 51
I liked Peter Mortenson's answer, but I would like to expand.
'cd ~' in the .bashrc file causes the "Git Bash Here" feature of Git Bash to stop working. Instead, add this if statement to the .bashrc file:
if [ "$PWD" == '/' ]
then
cd ~
fi
This will change to the home directory when Git Bash is run on its own, but when "Git Bash Here" is run, the current working directory will not be changed.
Upvotes: 4
Reputation: 4786
The working solution listed are great, but the problem occurs when you want multiple default home for your git-bash.
A simple workaround is to start git-bash using bat script.
cd C:\xampp\htdocs
"C:\Program Files\Git\git-bash.exe"
The above of course assume git-bash is installed at C:\Program Files\Git\git-bash.exe
You can create multiple .bat
file so your git-bash can start where it want to be
Upvotes: 2
Reputation: 5521
Git bash is used to play with bash commands. So I use bash method itself in windows Git bash
Edit your .bash_profile
(create it if you doesnot have one - see below how to create). Enter the following lines.
alias ws="cd /d/workspace/"
ws
Smilyface@SmilingMachine /d/workspace
$ cat ~/.bash_profile
alias ws="cd /d/workspace/"
ws
touch ~/.bash_profile
OR write into the file directly
vi ~/.bash_profile
Simple, aha !
Upvotes: 9
Reputation: 417
Windows 10 tested solution
Type git bash in search
Right click on it and choose open file location
Right click on it and choose properties
At target remove --cd-to-home from "C:\Program Files\Git\git-bash.exe" --cd-to-home
At start in put the path of the directory you want it to start at for example Start in: C:\xampp\htdocs
Upvotes: 26
Reputation: 1476
I read it somewhere and it worked for me.
First check in git bash what is the HOME location. Open git bash and run
echo $HOME
Now change the HOME path by opening cmd and run
setx HOME "path/to/.ssh/loc" (I gave C:\Users\aXXXX)
Now cross check by running the echo command in git bash.
Upvotes: 31
Reputation: 615
I am using Git bash on Windows 10, here is my solution:
env
; then click Edit environment variables for your account
(control panel)New
button~/
to be in git bashOpen a git bash session and test it by typing: pwd
and double check by doing cd ~/ && pwd
Upvotes: 9
Reputation: 63
I tried the following; it helped me. I hope it help you also.
cd /c/xampp/your-project
Upvotes: 0
Reputation: 3074
Add this line to your .bashrc
file:
cd C:/xampp/htdocs/<name of your project>;
If the .bashrc file doesn't exist, create one in your root folder. For me it is: C:\Users\tapas\
Save .bashrc and open Git Bash. That's it!
Upvotes: 196
Reputation: 111
Just type the path of your local directory (Git project home directory) in the properties of Git Bash. I.e. set path C:\yourprojsctdirectory to Git Bash's properties field "Execute In" or (Ausführen in). That's it!
Now double click Git Bash. The Git header will be on your "yourprojsctdirectory".
Upvotes: 2
Reputation: 512
Make a Git Bash shortcut to Desktop for convenience then right click on the icon goto properties. Here you will find the Start in: section with a text box. Replace the path you want, for example like:
%USERPROFILE%\Desktop
Then open it directly by clicking on the icon. You will get the default Desktop path in Git Bash.
Upvotes: 5
Reputation: 11
Add "cd your_repos_path" to your Git profile, which is under the %
.
Upvotes: 1
Reputation: 3239
If you're like me, and the way you get to Git is windows key + G + I + Enter, then you can simply hit the windows key, search for Git, right click on the resulting Git Bash
icon, select properties, and change the Start in:
field.
I'm not exactly sure what this does, because I'm not exactly sure what Git on Windows is (a facade on top of sh which itself is a facade on cmd?), but in any case, you can now pin the shortcut that Windows pulls up on a search for "Git" to your taskbar, or to your desktop, and it will still start in whatever directory you set it to.
Upvotes: 18
Reputation: 69545
After installing msysgit I have the Git Bash here
option in the context menu in Windows Explorer. So I just simply navigate to the directory and then open Bash right there.
I also copied the default Git Bash
shortcut to the desktop and edited its Start in
property to point to my project directory. It works flawlessly.
Windows 7x64, msysgit.
Upvotes: 252
Reputation: 245
Right click on Git Bash shortcut
and then go to properties
.
In properties
inside start in
option add the location of the directory you want to start Git Bash
in and apply
the changes.
Upvotes: 10
Reputation: 653
Once you have updated the Start in:
field make sure to remove the --cd-to-home
at the end of the Target:
field
Upvotes: 6
Reputation: 3505
Open the properties of the bash and change to "Start in" to where you want to start in. After this, (I had this problem and I solved it by doing this) go to target and delete the --cd-to-home parameter part after "C:\Program Files\Git\git-bash.exe" . Only THEN will you start in the "Start in" directory that you specified.
Upvotes: 24