简体   繁体   中英

git clone without project folder

I have given access to server, and want to clone git repo into my root folder. But when I do git clone it will make me folder with project name, and my project folder is my root. I dont have access to my parent folder my root is

/var/www/sites/mysite/

and when I do cloning folder structure will be

/var/www/sites/mysite/mysite

git clone accepts a last argument that is the destination directory, it is by default the name of the project but you can change it. In your case you probably want simply . :

$ git clone origin-url .

But note that, from man git-clone :

Cloning into an existing directory is only allowed if the directory is empty.

You can also just setup a new repo and then the tracking remote and branch:

git init .
git remote add origin git@github.com:user/repo.git
git fetch origin
git checkout master

This is working well on Windows also.

git init
git remote add origin git@github.com:user/repo.git
git pull origin master

Remember that a git repository is simply the directory structure where you store it. This means that when you clone a repository into the wrong directory, you can simply move the directory contents anywhere else that you wish and the repository data is still intact. So for example, you can run the following commands from the command line:

$ mv /var/www/sites/mysite/mysite/* /var/www/sites/mysite`
$ mv /var/www/sites/mysite/mysite/.* /var/www/sits/mysite`
$ rmdir /var/www/sites/mysite/mysite

您可以将项目克隆到子文件夹中,然后它们.git包括.git文件夹在内的所有文件移动到父文件夹(您的根)中。

git clone git@github.com:user/repo.git .

Notice the . at the end of that command.

Or Another way is

git init

git remote add origin git@github.com:user/repo.git

git pull origin master

The simplest way to achieve this is by initializing a Git repo in the directory you want to clone into and pull from the remote:

git init
git pull <remote-url>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM