Ошибка fatal destination path already exists and is not an empty directory

Explanation

This is pretty vague but I’ll do what I can to help.

First, while it may seem daunting at first, I suggest you learn how to do things from the command line (called terminal on OSX). This is a great way to make sure you’re putting things where you really want to.

You should definitely google ‘unix commands’ to learn more, but here are a few important commands to help in this situation:

ls — list all files and directories (folders) in current directory

cd <input directory here without these brackets> — change directory, or change the folder you’re looking in

mkdir <input directory name without brackets> — Makes a new directory (be careful, you will have to cd into the directory after you make it)

rm -r <input directory name without brackets> — Removes a directory and everything inside it

git clone <link to repo without brackets> — Clones the repository into the directory you are currently browsing.

Answer

So, on my computer, I would run the following commands to create a directory (folder) called projects within my documents folder and clone a repo there.

  1. Open terminal
  2. cd documents (Not case sensitive on mac)
  3. mkdir projects
  4. cd projects
  5. git clone https://github.com/seanbecker15/wherecanifindit.git
  6. cd wherecanifindit (if I want to go into the directory)

p.s. wherecanifindit is just the name of my git repository, not a command!

Давайте представим что мы хотим клонировать репозиторий с Git в текущую директорию проекта, делается это, путем указания точки в конце команды. В директории могут находится скрытые файлы и папки. Например .idea от phpStorm. В этом случае, мы получим ошибку:

Fatal: destination path '.' already exists and is not an empty directory

В таком случае, нужно будет полностью очистить директорию, куда вы клонируете репозиторий, а это приведет к определенным проблемам. Например если удалить директорию .idea, то мы удалим все настройки проекта в phpStorm.

Для того, чтобы избежать подобного рода проблем, находясь в нужной директории, можно воспользоваться следующим набором команд:

git init .
git remote add -f origin <repository-url>
git checkout <branch-name>

Описание того, что мы делаем:

  • Инициализируем пустой репозиторий в директории.
  • Добавляем удаленный репозиторий (вместо <repository-url>, укажите путь до репозитория).
  • Выбираем ветку с которой хотим работать.

В итоге Git сам обновит тот новосозданный нами репозиторий, в соответствии с удаленным, который мы указали во второй команде. Ну, а последней командой, мы просто укажем Git с какой веткой хотим работать и он подтянет версию проекта из этой ветки.

Вот такое альтернативное решение клонирования репозитория в текущую директорию, даже если она не пуста.

Время работы: 0,1330 s
Время запросов: 0,1330 s
Количество запросов: 30
Источник: cache

Дано: «ошибка» : «Fatal: destination path ‘.’ already exists and is not an empty directory.»

Решение:
Заходим в корень проекта, куда собираетесь делать git clone. Выполняем последовательно следующие команды: (и ставим лайк в конце статьи, без этого не сработает)

git init .
git remote add -t * -f origin <repository-url>
git checkout master

<repository-url> — ссылка на Ваш репозиторий, к примеру: https://github.com/IlyaVorozhbit/LinuxStart.git

После выполнения данных команд, в корне проекта будут нужные Вам файлы, которые Вы получили бы выполнив git clone, в случае не появления ошибки.

Успех! (ставьте лайк !! ) :D

The most common way to clone git repository is to enter in the terminal command that
looks like something like this:

git clone https://github.com/bessarabov/my_project.git

This command will create the directory «my_project» in the current directory and it will clone
repo to that directory. Here is an example:

$ pwd
/Users/bessarabov
$ git clone https://github.com/bessarabov/my_project.git
Cloning into 'my_project'...
remote: Enumerating objects: 3, done.
remote: Counting objects: 100% (3/3), done.
remote: Total 3 (delta 0), reused 0 (delta 0), pack-reused 0
Unpacking objects: 100% (3/3), done.
$ ls -1a my_project/
.
..
.git
README.md
$

Command «pwd» prints the directory where you are now. The command «git clone …» does the clone.
And with «ls» command we check that there is a hidden «.git» directory that stores all the history
and other meta information and there is a «README.md» file.

Specify directory to clone to

Sometimes you need to place git repository in some other directory. Here is an example:

$ pwd
/Users/bessarabov
$ git clone https://github.com/bessarabov/my_project.git project
Cloning into 'project'...
remote: Enumerating objects: 3, done.
remote: Counting objects: 100% (3/3), done.
remote: Total 3 (delta 0), reused 0 (delta 0), pack-reused 0
Unpacking objects: 100% (3/3), done.
$ ls -1a project
.
..
.git
README.md
$

As you can see here I used «git clone» command with two parameters:

  • the first paramter is the url to the repo
  • the second paramter is the directory where to clone repo

Clone to the current directory

And sometimes you need to clone the git repo to the current directory. To specify
the current directory the symbol dot is used. So to clone repo to the current
directory you need to specify two parameters to git clone:

  • the url of the repo
  • just one symbol — dot — «.» — it means current directory

Here is an example:

$ mkdir the_project
$ cd the_project/
$ pwd
/Users/bessarabov/the_project
git clone https://github.com/bessarabov/my_project.git .
Cloning into '.'...
remote: Enumerating objects: 3, done.
remote: Counting objects: 100% (3/3), done.
remote: Total 3 (delta 0), reused 0 (delta 0), pack-reused 0
Unpacking objects: 100% (3/3), done.
$ ls -1a
.
..
.git
README.md
$

Here I have created a new directory with the name «the_project», then I’ve entered it
with «cd» command and did the clone with the command «git clone url .». The dot in
this command is what makes git clone to the directory where I’m now.

Error «fatal: destination path ‘.’ already exists and is not an empty directory»

Sometimes you can see error message:

$ git clone https://github.com/bessarabov/my_project.git .
fatal: destination path '.' already exists and is not an empty directory.

It means exactly what it it written in this message. You are trying to checkout
repo to the directory that has some files in it. With the command «ls» you can check
what files are in the current directory. It is also possible that there are some
hidden files, so it is better to use «-a» option to make «ls» show all files
including hidden:

$ ls -1a
.
..
.git
README.md

The «ls» command shows that git is right. The directory is not empty. There is a
directory .git and a file README.md. You can permanent delete that files with
the command «rm» (but do it only if you don’t need those files, you will not
be able to «undelete» them):

$ rm -rf .git README.md

After that the «git clone» will succeed:

$ git clone https://github.com/bessarabov/my_project.git .
Cloning into '.'...
remote: Enumerating objects: 3, done.
remote: Counting objects: 100% (3/3), done.
remote: Total 3 (delta 0), reused 0 (delta 0), pack-reused 0
Unpacking objects: 100% (3/3), done.
$

Recap

  • When you use «git clone url» the directory will be automatically created
  • You can specify what directory to create with the command «git clone url dir»
  • If you need to clone to the current directory you need to run command «git clone url .»

Git is great for your own and team projects but what if you have a non-emtpy folder you want to clone into. This guide will help you to clone into it.

I’m building a few new projects. Some in just plain good old PHP and some with a nice framework like Slim 3. I’ve got a good working shared hosting solution at Vimexx and the only problem I have that when I git clone in a usually non empty directory I get these nice errors.

So here are the 5 simple steps to git clone in to that non empty folder!

You want to git clone in to that folder where there is already some files?

Let me guess. When you do:

git clone ssh://user@host.com/home/user/private/repos/project_hub.git .

You get a:

Fatal: destination path ‘.’ already exists and is not an empty directory.

So what are the options here?
If you do:

git help clone

You get:

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

No Shit! Sherlock!

So should you remove or move all the files and folders within the folder you want to clone into?

No!

Don’t worry! I’ve got you’re back!

The solution to Git Clone into a non empty folder is simple!

Solution to Git Clone into a non empty directory

The solution is very simple! Actually there are two solutions. Just see which one suits you!

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

or

git init .      
git remote add -t \* -f origin <repository-url>     
git checkout master

Git Clone

What is Git Clone? Git Clone, Clones a repository into a newly created directory, creates remote-tracking branches for each branch in the cloned repository, and creates and checks out an initial branch that is forked from the cloned repository’s currently active branch.

After the clone, a plain git fetch without arguments will update all the remote-tracking branches, and a git pull without arguments will in addition merge the remote master branch into the current master branch.

Executing the command git clone git@github.com:whatever creates a directory in a current folder named whatever, and drops the contents of the git repo into that folder. Use a dot (.) behind the command to place the files directly into the current folder.

  • Ошибка fatal application error
  • Ошибка fat32 на флешке
  • Ошибка fastman92 limit adjuster радмир
  • Ошибка fastman92 limit adjuster аризона рп
  • Ошибка fastboot на xiaomi что делать