Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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:

/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?

like image 525
David Smith Avatar asked Mar 16 '09 15:03

David Smith


People also ask

Can I just copy a git repository to another directory?

The correct command is rsync -azv --exclude '. git' source/ destination/ , which copies contents of source folder to destination folder.

How do I change the directory of a clone?

The fastest way to change the folder name when cloning a GitHub repository is to simply specify the name you want at the end of the git clone command. Here's a short video showing the entire process: When you're done downloading the repo do cd your-app-name to enter your directory with all the Create React App files.

Will git clone create a folder?

The standard approach to clone is repository is using the git-clone command. But when you simply clone a repository with git clone <repository> , it creates a new directory with repository name at the current path in the file system and clones the repository inside it.

How do I clone a git repository step by step?

From your repository page on GitHub, click the green button labeled Clone or download, and in the “Clone with HTTPs” section, copy the URL for your repository. Next, on your local machine, open your bash shell and change your current working directory to the location where you would like to clone your repository.


2 Answers

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.

like image 188
Can Berk Güder Avatar answered Sep 20 '22 08:09

Can Berk Güder


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 [email protected]:whatever . 

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

like image 23
J Wynia Avatar answered Sep 21 '22 08:09

J Wynia