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

29,186

Solution 1

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.

Solution 2

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.

Share:
29,186
Alium Britt
Author by

Alium Britt

Intermediate programmer in PHP, Python, and Javascript, mainly for use in application and web development. Starting to learn more low-level programming languages like Java (mainly for grad school). Worked with both MS SQL Server and MySQL databases. Just got accepted to a grad school program in intelligent systems/AI. Some experience with Byond, Unity3D and GameMaker. Bachelor's degree in Astronomy/Astrophysics. Native English speaker and English teacher with a TEFL certificate. Lived and worked in Japan for two and a half years teaching English and currently living and teaching in Spain.

Updated on December 17, 2021

Comments

  • Alium Britt
    Alium Britt over 2 years

    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.

  • Alium Britt
    Alium Britt almost 11 years
    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\"
  • hammar
    hammar almost 11 years
    @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.
  • Alium Britt
    Alium Britt almost 11 years
    Ok, I'll try it out. Thanks!
  • Alium Britt
    Alium Britt almost 11 years
    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!
  • Asif Mehmood
    Asif Mehmood about 9 years
    how to change the default direcory for cloned repository @hammar using bash shell
  • kayleeFrye_onDeck
    kayleeFrye_onDeck about 8 years
    @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.
  • Asif Mehmood
    Asif Mehmood about 8 years
    Yes that (in above comment) was the solution to my problem. Had done it long long time ago :-) Thank you @kayleeFrye_onDeck
  • Adam
    Adam over 2 years
    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 more