繁体   English   中英

我可以更改本地驱动器上所有Git活动的默认目录吗?

[英]Can I change the default directory on my local drive for all Git activity?

所以我才开始使用Git和GitHub。 它仍然是一个陡峭的攀爬,但我开始喜欢它。 我在克隆存储库时注意到的一件事是,它总是下载到我的主文件夹/users/username 有办法改变吗?

我在Git手册中进行了搜索,并认为我可能可以使用--git-dir=GIT_DIR ,但是我知道我使用的方式不正确,因为当我尝试执行此操作时,Terminal中返回的内容是

       git --git-dir=New/Directory/Path/
usage: git [--version] [--exec-path[=GIT_EXEC_PATH]] [--html-path]
           [-p|--paginate|--no-pager] [--no-replace-objects]
           [--bare] [--git-dir=GIT_DIR] [--work-tree=GIT_WORK_TREE]
           [--help] COMMAND [ARGS]

The most commonly used git commands are:
   add        Add file contents to the index
   bisect     Find by binary search the change that introduced a bug
   branch     List, create, or delete branches
   checkout   Checkout a branch or paths to the working tree
   clone      Clone a repository into a new directory
   commit     Record changes to the repository
   diff       Show changes between commits, commit and working tree, etc
   fetch      Download objects and refs from another repository
   grep       Print lines matching a pattern
   init       Create an empty git repository or reinitialize an existing one
   log        Show commit logs
   merge      Join two or more development histories together
   mv         Move or rename a file, a directory, or a symlink
   pull       Fetch from and merge with another repository or a local branch
   push       Update remote refs along with associated objects
   rebase     Forward-port local commits to the updated upstream head
   reset      Reset current HEAD to the specified state
   rm         Remove files from the working tree and from the index
   show       Show various types of objects
   status     Show the working tree status
   tag        Create, list, delete or verify a tag object signed with GPG

See 'git help COMMAND' for more information on a specific command.

所以一定是错的...

除非另有指定,否则git clone会将文件复制到当前目录中。 因此,如果当前工作目录为~ ,则

$ git clone me@host:/path/to/repo.git

会将文件复制到~/repo

您可以通过以下两种方式之一进行更改:

cd到所需目录:

$ cd /path/to/my/files
$ git clone me@host:/path/to/repo.git

将在/path/to/my/files/repo创建您的/path/to/my/files/repo

或者, git clone可以采用指定位置的参数:

$ git clone me@host:/path/to/repo.git /other/path/to/repo

将在/other/path/to/repo创建您的/other/path/to/repo

在Linux中键入pwd (打印工作目录)。 这将显示git clone将文件下载到的目录。

默认情况下,命令提示符将位于~目录(即主目录)中。

您可以执行cd /home/barackObama/websites/whitehouse; git clone...... cd /home/barackObama/websites/whitehouse; git clone......克隆到whitehouse文件夹中。

正如@mipadi所说,您可以在执行克隆操作时修改结帐位置:

git clone git://some.path/goes/here some/local/path/here

但是我感觉到您想要一个更永久的解决方案。

--git-dir选项设置到存储库的路径,我正在按命令读取它与(本地)存储库位置相关的内容,而不是某些全局设置。 您可能在config文件中可以执行某些操作 ,但是我什么都不知道。

我在这里找到了一种简单的方法:

在快捷方式Git Bash上按鼠标右键,然后在其中更改开始位置:输入所需的启动目录。 确认。 做完了!

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM