How to change git shell's start directory in windows 7
Asked Answered
T

6

37

I downloaded and installed the programs offered by GitHub including Git Shell.

The problem is that I want to set up the home directory of the Git Shell program to a custom one, but I don't know how to do that.

I tried changing the "start in" field from the properties menu of the Git Shell shortcut but it didn't work.

Can anybody please give me some information on how to change the home directory of the Git Shell to a custom one?

Taproot answered 10/9, 2013 at 19:8 Comment(3)
GitHub for Windows can be configured to use a number of different shell programs, and I don't remember which is the default. Are you using PowerShell, cmd, or bash?Applicant
I am using powershell.Taproot
In case you are using cmd you can set on path in the syntax to set your start directory.Arran
B
47

1.Open GitHub Windows client.

2.Click tools (at the top of the window) and select 'Options'.

enter image description here

3.There you will find 'default storage location'. This is where Git Shell starts when you run it.

enter image description here

Barrier answered 20/2, 2014 at 18:7 Comment(3)
Maybe this doesn't work anymore? My (new) github version calls "default storage directory" above "Clone path" instead. The path I entered there only shows up as "Local Path" under the "+" sign in the GUI. The solution that worked for me is in my comment to @ssmith 's answer below.Oomph
After updating github for windows yesterday (to Version 2.14.7) I have found that powershell no longer sets the home directory to "Clone path". The solution is much simper than described in the answers below; edit the shortcut and add the directory path after the --open-shell parameter, like this --open-shell=c:\whateverAer
Using GitHub Desktop 3.0.7.1, this seems to work again.Bondie
C
50
  1. Right click on Git Shell
  2. Choose Properties
  3. Move to the end of the Target field
  4. Change --open-shell to --open-shell=c:\your_dir
Claro answered 17/7, 2015 at 4:41 Comment(7)
This did it for me, also allowed me to configure lots of shortcuts for different Git shellsDihybrid
Definitely the right answer, accepted answer doesn't work anymore.Bokbokhara
Note that you can't use double quotes around your directory name.Petition
@ErikSchierboom I know this is an old post, but since quotes can't be used, is there a solution/workaround for filepaths that contain spaces? (Beyond the obvious "change the path so it doesn't have spaces")Kinard
@Kinard If so, I haven't been able to find one. Single quotes also don't work.Petition
@Kinard I haven't tried it myself, but maybe short / "8.3" directory names would work? superuser.com/q/348079/6581Rind
Worked for me with the 8.3 "short" directory name (for setting a shortcut in Total Commander, use %p)Sawtoothed
B
47

1.Open GitHub Windows client.

2.Click tools (at the top of the window) and select 'Options'.

enter image description here

3.There you will find 'default storage location'. This is where Git Shell starts when you run it.

enter image description here

Barrier answered 20/2, 2014 at 18:7 Comment(3)
Maybe this doesn't work anymore? My (new) github version calls "default storage directory" above "Clone path" instead. The path I entered there only shows up as "Local Path" under the "+" sign in the GUI. The solution that worked for me is in my comment to @ssmith 's answer below.Oomph
After updating github for windows yesterday (to Version 2.14.7) I have found that powershell no longer sets the home directory to "Clone path". The solution is much simper than described in the answers below; edit the shortcut and add the directory path after the --open-shell parameter, like this --open-shell=c:\whateverAer
Using GitHub Desktop 3.0.7.1, this seems to work again.Bondie
P
7

When I use @ssmith's answer it opens up in the right directory but does not have any of the features of posh-git. When I open it up normally it say s posh-git in the title, when I add this configuration it just says powershell...

I figured it out, use/create the file

C:\Users\yourUserName\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1

(the default profile) and then add the line mentioned above

Set-Location C:\Your\Start\Directory

Politician answered 9/10, 2013 at 15:18 Comment(2)
This will set location for every Powershell window not only Github for Windows Powershell right?Barrier
I can't confirm that for you, I've a different setup now, but I assume so.Politician
W
3

According the article below (in the "Posh-Git and PowerShell" section) you should be able to create a Documents\WindowsPowerShell\GitHub.PowerShell_profile.ps1 file that will start when your GitHub PowerShell starts. In that file you can add the Set-Location c:\path\to\repo command.

For what it's worth, in case anyone comes across this but has a Bash shell, adding the command cd /path/to/repo to ~/.basrc should do the trick.

http://haacked.com/archive/2012/05/21/introducing-github-for-windows.aspx

Welfarism answered 2/10, 2013 at 22:30 Comment(2)
When I name the file "GitHub.PowrShell_profile.ps1", I lose the posh-git exactly as @BunnyStrider mentions in his answer.Fanchette
@DavidPeden I just figured out the next step. It's literally the next step in the article above. Add the lines in the "Custom Shell" section to your GitHub.PowerShell and it will load posh-git. It took me most of the day to figure all this out. RTFM, sure... but which one?Oomph
P
2

Piotr Perak directions are accurate. however, for newer versions, you have to update the "Clone Path".


  1. Launch GitHub for windows.

  1. Click "Tools and Options" gear at top right > Options

  1. Change "Clone Path" to the directory you would like git to open at. Please see image below. Thank you.

enter image description here

Perimeter answered 13/6, 2016 at 22:31 Comment(0)
M
1

Other answers didn't work for me, and I am on Windows 10. So for those looking for another way I added a line to my ~/.bashrc: cd /c/myfoldername

Works like a charm

Mincemeat answered 6/6, 2018 at 16:18 Comment(1)
Mmm, but what if then you execute cd ~ ?Talamantes

© 2022 - 2024 — McMap. All rights reserved.