git clone without project folder
LinuxGitLinux Problem Overview
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
Linux Solutions
Solution 1 - Linux
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.
Solution 2 - Linux
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
Solution 3 - Linux
This is working well on Windows also.
git init
git remote add origin git@github.com:user/repo.git
git pull origin master
Solution 4 - Linux
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
Solution 5 - Linux
You can clone your project into subfolder and them move all files including the .git
folder into the parent folder (your root).
Solution 6 - Linux
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>