Git/GitHub - 更改克隆存储库的默认位置而不更改 HOME 变量?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16764913/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 16:14:37  来源:igfitidea点击:

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

gitgithub

提问by Alium Britt

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>).

我仍在学习 Git 和 GitHub,到目前为止我还没有弄清楚这一点。我在 GitHub 上找到了一个我想尝试编辑的公共存储库,所以我对存储库进行了分叉,然后克隆了它,这样我就有了文件的本地副本可以使用。我不得不在网上搜索了一段时间才能弄清楚 Git 将本地文件放在哪里,但我最终在 C:\Users\\Documents\GitHub 下的各自子文件夹中找到了这些文件(我有 Windows 7 - 对于其他版本Windows 的文件显然在 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.

在设置 GitHub 时,我能够选择存储库位置,但显然该位置仅影响我创建的存储库,而不影响我克隆的存储库。我想尝试找出一种更改默认克隆目录位置的方法,但听起来唯一的方法是更改​​ HOME 环境变量。但是,更改也可能影响其他程序的环境变量听起来不像是最佳实践,所以我希望有另一种方法。

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?

有没有办法在不修改 HOME 环境变量的情况下做到这一点,也不需要每次都输入它(这会导致拼写错误),或者在命令行中指定位置可能是最好的方法?

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

编辑:我使用 GitHub for Windows GUI 和 Powershell。

采纳答案by Blender

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

您说过您正在使用 GitHub for Windows 应用程序,因此您可以在设置对话框中对其进行配置。打Alt-T,按选项,然后你可以改变默认的存储目录

回答by hammar

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\GitHubdirectory by default. If it's the regular cmd.exeprompt, you should be able to configure this in the properties window of the shortcut you're using to open it.

默认情况下,Git 将克隆到当前目录的一个新子目录中,因此您可以简单地设置您使用的任何 shell/终端C:\Users\\Documents\GitHub,默认情况下在该目录中启动。如果是常规cmd.exe提示,您应该能够在用于打开它的快捷方式的属性窗口中进行配置。