问题
I'm doing:
git clone ssh://user@host.com/home/user/private/repos/project_hub.git ./
I'm getting:
Fatal: destination path '.' already exists and is not an empty directory.
I know path . already exists. And I can assure that directory IS empty. (I do ls inside and I see nothing!)
What am I missing here in order to clone that project into the current directory ?
回答1:
simply put a dot next to it
git clone git@github.com:user/my-project.git .
From git help clone
:
Cloning into an existing directory is only allowed if the directory is empty.
So make sure the directory is empty (check with ls -a
), otherwise the command will fail.
回答2:
The following is probably not fully equivalent to a clone in all cases but did the trick for me:
git init .
git remote add -t \* -f origin <repository-url>
git checkout master
In my case, this produces a .git/config
file which is equivalent to the one I get when doing a clone.
回答3:
@Andrew has answered it clearly here. But as simple as this also works even if the directory is not empty:
git init .
git remote add origin <repository-url>
git pull origin master
回答4:
To be sure that you could clone the repo, go to any temporary directory and clone the project there:
git clone ssh://user@host.com/home/user/private/repos/project_hub.git
This will clone your stuff into a project_hub
directory.
Once the cloning has finished, you could move this directory wherever you want:
mv project_hub /path/to/new/location
This is safe and doesn't require any magical stuff around.
回答5:
git clone your-repo tmp && mv tmp/.git . && rm -rf tmp && git reset --hard
回答6:
Do
git clone https://user@bitbucket.org/user/projectname.git .
Directory must be empty
回答7:
If the current directory is empty, then this will work:
git clone <repository> foo; mv foo/* foo/.git* .; rmdir foo
回答8:
In addition to @StephaneDelcroix's answer, before using:
git clone git@github.com.user/my-project.git .
make sure that your current dir is empty by using
ls -a
回答9:
Solution:
On this case, the solution was using the dot
,
so: rm -rf .* && git clone ssh://user@host.com/home/user/private/repos/project_hub.git .
rm -rf .* &&
may be omitted if we are absolutely sure that the directory is empty.
Credits go to: @James McLaughlin on comments below.
回答10:
Improving on @GoZoner's answer:
git clone <repository> foo; shopt -s dotglob nullglob; mv foo/* .; rmdir foo
The shopt command is taken from this SO answer and changes the behavior of the 'mv' command on Bash to include dotfiles, which you'll need to include the .git directory and any other hidden files.
Also note that this is only guaranteed to work as-is if the current directory (.) is empty, but it will work as long as none of the files in the cloned repo have the same name as files in the current directory. If you don't care what's in the current directory, you can add the -f (force) option to the 'mv' command.
回答11:
I had this same need. In my case I had a standard web folder which is created by a web server install. For the purposes of this illustration let's say this is
/server/webroot
and webroot contains other standard files and folders. My repo just has the site specific files (html, javascript, CFML, etc.)
All I had to do was:
cd /server/webroot
git init
git pull [url to my repo.git]
You need to be careful to do the git init in the target folder because if you do NOT one of two things will happen:
- The git pull will simply fail with a message about no git file, in my case:
fatal: Not a git repository (or any of the parent directories): .git
- If there is a .git file somewhere in the parent path to your folder your pulled repo will be created in THAT parent that contains the .git file. This happened to me and I was surprised by it ;-)
This did NOT disturb any of the "standard" files I have in my webroot folder but I did need to add them to the .gitignore file to prevent the inadvertent addition of them to subsequent commits.
This seems like an easy way to "clone" into a non-empty directory. If you don't want the .git and .gitignore files created by the pull, just delete them after the pull.
回答12:
Hmm... specifing the absolute current path using $(pwd)
worked for me.
git clone https://github.com/me/myproject.git $(pwd)
git version: 2.21.0
回答13:
Further improving on @phatblat's answer:
git clone --no-checkout <repository> tmp \
&& mv tmp/.git . \
&& rmdir tmp \
&& git checkout master
as one liner:
git clone --no-checkout <repository> tmp && mv tmp/.git . && rmdir tmp && git checkout master
回答14:
use .(dot) at the end of your command like below
git clone URL .
回答15:
shopt -s dotglob
git clone ssh://user@host.com/home/user/private/repos/project_hub.git tmp && mv tmp/* . && rm -rf tmp
回答16:
Removing with
rm -rf .*
may get you into trouble or some more errors.
If you have /path/to/folder, and would like to remove everything inside, but not that folder, just run:
rm -rf /path/to/folder/*
回答17:
Here was what I found:
I see this:
fatal: destination path 'CouchPotatoServer' already exists and is not an empty directory.
Amongst my searchings, I stumbled on to:
https://couchpota.to/forum/viewtopic.php?t=3943
Look for the entry by Clinton.Hall...
If you try this (as I did), you will probably get the access denied
response, there was my 1st clue, so the initial error (for me), was actually eluding to the wrong root issue.
Solution for this in windows:
make sure you run cmd
or git elevated
, then run:
git clone https://github.com/RuudBurger/CouchPotatoServer.git
The above was my issue and simply elevating worked for me.
回答18:
it's useful to create a new file by mkdir filename
,then running the command of git clone xxxxx
,it does work in my computer
回答19:
So I fixed this same error by deleting the hidden .git folder in my root directory, and then adding a period to the 'git clone repo .' in my root/dist folder. This is in the context of a vue-cli webpack project. So what everyone else is saying is right, it usually means you have git tracking either in the folder you are trying to clone into or in the parent folder or root of the folder in question!
回答20:
The solution for Windows
is to clone the repository to other folder and then copy and paste to the original location or just copy the .git
invisible folder.
回答21:
Just delete (or move) contents including .git
directory, of the given directory.
Automated tools like Android studio's Rebuild
will solve the issue for you.
More details:
Error shown for me was for jarresolver
git repo
path shown is temp\jarresolver\
I just deleted contents of temp\jarresolver\
directory, including the hidden .git
directory.
That's all, all worked, no cloning required.
When I did Rebuild
, Android studio clone itself & build got successful.
回答22:
if repo is private first add your ssh key use => git clone git@github.com:yourusername/yourrepo.git else use => git clone https://github.com/yourusername/yourrepo.git
回答23:
I have seen this question so many times - and I just want to point out that git pull
from within your directory will do the trick.
Unless I'm missing something here - that worked for me.
来源:https://stackoverflow.com/questions/9864728/how-to-get-git-to-clone-into-current-directory