How do you clone a Git repository into a specific folder?

David Smith picture David Smith · Mar 16, 2009 · Viewed 2M times · Source

Executing the command git clone [email protected]:whatever creates a directory in my current folder named whatever, and drops the contents of the Git repository into that folder:

/httpdocs/whatever/public

My problem is that I need the contents of the Git repository cloned into my current directory so that they appear in the proper location for the web server:

/httpdocs/public

I know how to move the files after I've cloned the repository, but this seems to break Git, and I'd like to be able to update just by calling git pull. How can I do this?

Answer

Can Berk Güder picture Can Berk Güder · Mar 16, 2009

Option A:

git clone [email protected]:whatever folder-name

Ergo, for right here use:

git clone [email protected]:whatever .

Option B:

Move the .git folder, too. Note that the .git folder is hidden in most graphical file explorers, so be sure to show hidden files.

mv /where/it/is/right/now/* /where/I/want/it/
mv /where/it/is/right/now/.* /where/I/want/it/

The first line grabs all normal files, the second line grabs dot-files. It is also possibe to do it in one line by enabling dotglob (i.e. shopt -s dotglob) but that is probably a bad solution if you are asking the question this answer answers.

Better yet:

Keep your working copy somewhere else, and create a symbolic link. Like this:

ln -s /where/it/is/right/now /the/path/I/want/to/use

For your case this would be something like:

ln -sfn /opt/projectA/prod/public /httpdocs/public

Which easily could be changed to test if you wanted it, i.e.:

ln -sfn /opt/projectA/test/public /httpdocs/public

without moving files around. Added -fn in case someone is copying these lines (-f is force, -n avoid some often unwanted interactions with already and non-existing links).

If you just want it to work, use Option A, if someone else is going to look at what you have done, use Option C.