开发者

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

So I just started using Git and GitHub. It's still a steep climb, but I'm starting to enjoy it. One thing I've noticed from when I clone a repository is that it always downloads to my home folder /users/username. Is there a way to change this?

I went searching through the Git manual and thought I might be able to use --git-dir=GIT_DIR, but I know I'm using it incorrectly because when I try this out what returns in Terminal is

       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 curr开发者_开发技巧ent 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.

So it must be wrong...


git clone will copy files to whatever your current directory is, unless you specify otherwise. So if your current working directory is ~, then

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

will copy files to ~/repo.

You can change this one of two ways:

cd to the desired directory first:

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

will create your repo at /path/to/my/files/repo.

Or, git clone can take an argument that specifies the location:

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

will create your repo at /other/path/to/repo.


As @mipadi said you can modify the checkout location when you do a clone:

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

but I get the feeling that you want a more permanent solution.

The --git-dir option sets the path to the repository, which I'm reading as a per-command thing that relates to the location of the (local) repo, rather than some global setting. There might be something that you can do in the config file, but I'm not aware of anything.


Type pwd (print working directory) in linux. That will show you the directory that git clone will download the files to.

By default the command prompt will be in the ~ directory, which is the home directory.

You can do cd /home/barackObama/websites/whitehouse; git clone...... to clone into the whitehouse folder.


I found an easy way to do it here:

Press the right mouse button on the shortcut Git Bash and there change the start in field: enter your desired startup directory. Confirm. Done!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜