Search code examples
gitrepositorygit-clone

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


The command git clone [email protected]:whatever creates a directory named whatever containing a Git repository:

./
    whatever/
        .git

I want the contents of the Git repository cloned into my current directory ./ instead:

./
    .git

Solution

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