How do you clone a Git repository into a specific folder?
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:
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:
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?
git clone [email protected]:whatever folder-name
right here use:
git clone [email protected]:whatever .
.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.
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 you 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.
Read more... Read less...
Basic Git Repository Cloning
You clone a repository with
git clone [url]
For example, if you want to clone the Stanford University Drupal Open Framework Git library called open_framework, you can do so like this:
$ git clone git://github.com/SU-SWS/open_framework.git
That creates a directory named open_framework (at your current local file system location), initializes a .git directory inside it, pulls down all the data for that repository, and checks out a working copy of the latest version. If you go into the newly created open_framework directory, you’ll see the project files in there, ready to be worked on or used.
Cloning a Repository Into a Specific Local Folder
If you want to clone the repository into a directory named something other than open_framework, you can specify that as the next command-line option:
$ git clone git:github.com/SU-SWS/open_framework.git mynewtheme
That command does the same thing as the previous one, but the target directory is called mynewtheme.
Git has a number of different transfer protocols you can use. The previous example uses the git:// protocol, but you may also see http(s):// or [email protected]:/path.git, which uses the SSH transfer protocol.
To clone git repository into a specific folder, you can use
-C <path> parameter, e.g.
git -C /httpdocs clone [email protected]:whatever
Although it'll still create a
whatever folder on top of it, so to clone the content of the repository into current directory, use the following syntax:
cd /httpdocs git clone [email protected]:whatever .
Note that cloning into an existing directory is only allowed when the directory is empty.
Since you're cloning into folder that is accessible for public, consider separating your Git repository from your working tree by using
--separate-git-dir=<git dir> or exclude
.git folder in your web server configuration (e.g. in
To clone to Present Working Directory:
git clone https://github.com/link.git
To clone to Another Directory:
git clone https://github.com/link.git ./Folder1/Folder2
Hope it Helps :)