Git/GitHub - change default location for cloned repository without changing HOME variable?
Asked Answered
D

3

6

I'm still learning Git and GitHub and I haven't been able to figure this out so far. I found a public repository on GitHub that I wanted to try editing, so I forked the repository and then cloned it so I'd have a local copy of the files to work with. I had to search for a while online to figure out where exactly Git puts the local files, but I ended up finding the files in their respective subfolders under C:\Users\\Documents\GitHub (I have Windows 7 -- for other versions of Windows the files are apparently in C:\Documents and Settings\< current_user>).

When setting up GitHub I was able to select a repository location, but apparently that location only affects repositories I create, not repositories I clone. I wanted to try and figure out a way to change the default cloned directory location, but it sounds like the only way to do this is to change the HOME environment variable. However, changing an environment variable that could also affect other programs does not sound like best practice so I'm hoping there's another way.

I found one way to do this by simply specifying the desired path every time I enter a clone command, like this:

git clone https://github.com/username/example.git c:/other/path/to/repo

Is there a way to do this without modifying the HOME environment variable and without typing it out every time (which invites typo errors), or is specifying the location in the command line probably the best way?

EDIT: I'm using the GitHub for Windows GUI and Powershell.

Derivative answered 27/5, 2013 at 0:19 Comment(8)
Are you using the GitHub for Windows GUI? Or are you cloning through the bash shell?Melchizedek
Yes, I'm using the GitHub for Windows GUI and the shell tool that comes with it, Powershell. It seems to have nearly the same functionality as cmd.exe.Derivative
Open up the UI, hit Tools, then options... and change the default storage directory.Melchizedek
Ahhhh, that's it! I opened up the Tools before and didn't see it, but apparently that menu does not show the option to change the default storage location unless I open it on the Dashboard. Yay thanks!! Only one problem - I can't mark this as the answer when it's a comment ...Derivative
Ah, my mistake, Powershell is a separate command line program - it's not part of the GitHub Windows GUI.Derivative
If I'm not mistaken, you can still run Git from Powershell (or I might be confusing that with Cygwin).Melchizedek
Yes, I cloned these repositories using Powershell, so it seems to work just fine.Derivative
The way to do this now is here: https://mcmap.net/q/1778380/-github-desktop-how-to-change-default-storage-directoryTriennial
M
3

You said that you're using the GitHub for Windows application, so you can configure it within the settings dialog. Hit Alt-T, press options and then you can change the default storage directory.

Melchizedek answered 27/5, 2013 at 0:50 Comment(2)
That worked! And after changing the default storage directory, I simply moved the cloned repositories I'd already downloaded to the new default location, and then used the option under Tools > Options to discover new repositories on my harddrive. It immediately found the two clone repositories I just moved and linked them up. Thanks!Derivative
This was an obviously important core feature for basic useage of the app, so ... of course they deleted it :(. The setting no longer exists (also 'Alt-T' appears to have been replace, there are no menus mapped to that shortcot). This answer was correct years ago but doesn't work any morePowys
T
3

Git will by default clone into a new subdirectory of the current directory, so you could simply set up whatever shell/terminal you're using to start in the C:\Users\\Documents\GitHub directory by default. If it's the regular cmd.exe prompt, you should be able to configure this in the properties window of the shortcut you're using to open it.

Timothee answered 27/5, 2013 at 0:34 Comment(5)
How would I configure the shortcut to open the directory I want? Make a shortcut to cmd.exe on my desktop and then in the Target line on the Properties window do something like this? C:\Windows\System32\cmd.exe /K "cd C:\Windows\"Derivative
@AliumBritt: It's been a while since I used Windows, but I believe there used to be a field named "current directory" that you could set.Timothee
how to change the default direcory for cloned repository @Timothee using bash shellTruffle
@MalikAsif if you don't already have a .bashrc file in %userprofile%, make one. just cd $userprofile then echo d>.bashrc, then open .bashrc in a text editor, remove the letter d, and paste this in, and modify as-needed: gdd='/c/path/to/mydefault/dir' then paste in gcl(){ cd $gdd && git clone $1 } The just use the terminal with gcl githubURL So something like gcl [email protected]:defunkt/github-gem.git Would work. Make sure to use linebreaks in the bashrc file with that function's curly braces, or it will throw errors.Cratch
Yes that (in above comment) was the solution to my problem. Had done it long long time ago :-) Thank you @CratchTruffle
M
3

You said that you're using the GitHub for Windows application, so you can configure it within the settings dialog. Hit Alt-T, press options and then you can change the default storage directory.

Melchizedek answered 27/5, 2013 at 0:50 Comment(2)
That worked! And after changing the default storage directory, I simply moved the cloned repositories I'd already downloaded to the new default location, and then used the option under Tools > Options to discover new repositories on my harddrive. It immediately found the two clone repositories I just moved and linked them up. Thanks!Derivative
This was an obviously important core feature for basic useage of the app, so ... of course they deleted it :(. The setting no longer exists (also 'Alt-T' appears to have been replace, there are no menus mapped to that shortcot). This answer was correct years ago but doesn't work any morePowys
C
0

With the new version of SourceTree, the default storage directory is no longer a named option; but it has been renamed as Project Folder.

Tools >> Options >> General >> Repo Settings >> Project folder

Chequerboard answered 16/12, 2021 at 14:3 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.