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

ID : 253

viewed : 143

Tags : gitrepositorygit-clonegit





Top 5 Answer for How do you clone a Git repository into a specific folder?

vote vote

91

Option A:

git clone git@github.com:whatever folder-name 

Ergo, for right here use:

git clone git@github.com: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.

vote vote

81

The example I think a lot of people asking this question are after is this. If you are in the directory you want the contents of the git repository dumped to, run:

git clone git@github.com:whatever . 

The "." at the end specifies the current folder as the checkout folder.

vote vote

77

Go into the folder.. If the folder is empty, then:

git clone git@github.com:whatever . 

else

git init git remote add origin PATH/TO/REPO git fetch git checkout -t origin/master 
vote vote

60

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 user@server:/path.git, which uses the SSH transfer protocol.

vote vote

60

To clone git repository into a specific folder, you can use -C <path> parameter, e.g.

git -C /httpdocs clone git@github.com: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 git@github.com: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 .htaccess file).

Top 3 video Explaining How do you clone a Git repository into a specific folder?







Related QUESTION?