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.
- Open terminal
cd documents(Not case sensitive on mac)mkdir projectscd projectsgit clone https://github.com/seanbecker15/wherecanifindit.gitcd 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,1138 s
Время запросов: 0,1138 s
Количество запросов: 28
Источник: cache
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.
We have exactly this issue in the last two build jobs in our build matrix. We have tried to resolve the issue at first, but now we would be happy if we could just workaround the issue.
Below are the summary of our issue and the actions have taken:
We have 12 jobs in our build matrix in Linux build environment. We have encountered mysterious «killed» apt-get install process for the last two jobs (can be either one of the two or sometimes both). However, after all the jobs were completed, rerunning the error-ed job would result in a successful build every times. So, my conclusion: it is intermittent.
We then switched around our installation step in our job, we switched our apt-get install step (which was the last installation step previously) with git clone step. So, now git clone is the last step and interestingly it is also now the process that get «killed». My conclusion: the root cause is internal to Travis-CI and not external parties (neither GitHub nor apt-get mirror) and also not pertinent to the command being used (neither git nor apt-get).
Attempting to use travis_retry function as per this blog recommendation also did not help. We soon realize that the naive travis_retry git clone would never going to work on retry, so we change to this: travis_retry bash -c 'if [ -d rpi-tools ]; then rm -rf rpi-tools && sleep 60; fi && git clone ...'. Although that helps in performing the git clone retrying, each retries process still got killed. We have added the sleep command in the hope that whatever the root cause for the killed process would clear away but apparently it did not help too.
Lastly we added memory diagnostics free -m into the mix just before each git clone. Finally we saw some tell tale sign of what causing the issue. On the build environment that bound to have the process killed, the free -m shows there are problem with kernel cache and reduced size of free memory. See the detail in the last comment on our issue log here.
The error-ed job keeps sending us false alarm to this day. As our last attempt, we tried to setup our build matrix to set the last two jobs to allow_failures. However, to our frustration that did not work too! When the process killed, it still being reported as error. Perhaps Travis-CI should have allow_errors too, but that’s another issue.
I hope the free -m output could shed some light in finding the actual root cause. If I am allowed to jump conclusion again then I would say: the process got killed because VM is running low on memory.
- HowTo
- Git Howtos
- Clone Into a Non-Empty Git Directory
This article will teach how to clone a Git repository to a non-empty folder. This action comes in handy when you want to merge the files in your remote repository with the files in your current local repository.
Clone Into a Non-Empty Git Directory in Git
Cloning a remote repository is easy. We use the command below.
git clone <repository-url> <directory>
This will clone the remote repository to the specified directory. However, the directory should be empty.
You will get a Fatal warning message if you try to clone in a non-empty repo, as shown below.
pc@JOHN MINGW64 ~/Git (main)
$ git clone https://github.com/Wachira11ke/Delftscopetech.git
fatal: destination path 'Delftscopetech' already exists and is not an empty directory.
Since the directory Delftscopetech already exists and contains some files, we cannot use the git clone command to clone our repository.
If you don’t need the files in the directory, you can delete them, but if you want to merge the files in both repositories, use the method below.
-
Open the directory you want to clone your remote repository into.
-
Set up a new repository with this command.
-
Add the remote repository
git remote add origin https://github.com/Wachira11ke/Delftscopetech.git -
Pull and merge
git pull origin main --allow-unrelated-histories
Example:
pc@JOHN MINGW64 ~/Git (main)
$ cd Delftscopetech1
pc@JOHN MINGW64 ~/Git/Delftscopetech1 (main)
$ git init
Initialized empty Git repository in C:/Users/pc/Git/Delftscopetech1/.git/
pc@JOHN MINGW64 ~/Git/Delftscopetech1 (master)
$ git remote add origin https://github.com/Wachira11ke/Delftscopetech.git
pc@JOHN MINGW64 ~/Git/Delftscopetech1 (master)
$ git pull origin master --allow-unrelated-histories
fatal: couldn't find remote ref master
pc@JOHN MINGW64 ~/Git/Delftscopetech1 (master)
$ git pull origin main --allow-unrelated-histories
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), 610 bytes | 3.00 KiB/s, done.
From https://github.com/Wachira11ke/Delftscopetech
* branch main -> FETCH_HEAD
* [new branch] main -> origin/main
We have successfully cloned our remote repo to our local repository with a non-empty directory.


John is a Git and PowerShell geek. He uses his expertise in the version control system to help businesses manage their source code. According to him, Shell scripting is the number one choice for automating the management of systems.
Related Article — Git Clone

Open
Issue created Sep 04, 2019 by
fatal: destination path ‘/my/path’ already exists and is not an empty directory.
Summary
I have two jobs. First job displays information about the repository. The second job clones another repository because it’s needed as a dependency to compile the code. The first time a pipeline is created, it completes both jobs successfully. The second time a pipeline is created, the second job fails because the directory where the dependency repository is cloned into is already there, from the first pipeline. Thereby generating the error: fatal: destination path ‘/my/path’ already exists and is not an empty directory.
Steps to reproduce
Create a job that clones a repository into the /builds directory. Run it twice, and the second time should fail since the cloned repo is still present.
.gitlab-ci.yml
stage: dependencies
script:
- git clone https://gitlab-ci-token:${CI_JOB_TOKEN}@gitlab.com/staging-fw/my_dependencies.git /builds/dependencies
Actual behavior
The second time a pipeline is created, the /builds directory already contains the /builds/dependencies folder.
Expected behavior
Since I’m using docker, my expectation is that the Docker container created for the pipeline will be blank and not contain any previous folders/files that were used in previous containers. That is obviously not the case since the /builds directory used by gitlab-runner contains previous content and is shared among every pipeline that is created.
Relevant logs and/or screenshots
job log
on old_gen_runner 6fsjs96e
Using Docker executor with image gcc-arm_4_7-2013q3:3.0 ...
Using docker image sha256:5d4741a428654beb44a3c004822e4d2ceededc88f22ec1ec7f45dedf707a0302 for gcc-arm_4_7-2013q3:3.0 ...
Running on runner-6fsjs96e-project-13664495-concurrent-0 via my_laptop.local...
Fetching changes with git depth set to 50...
Initialized empty Git repository in /builds/staging-fw/my-project/.git/
Created fresh repository.
From https://gitlab.com/staging-fw/my-project
* [new branch] master -> origin/master
Checking out 139f4bdd as master...
Skipping Git submodules setup
$ python /scripts/info.py
Printing job info...
Builds dir: /builds
Commit Message:
Modified yml file.
Branch: master
Project dir: /builds/staging-fw/my-project
$ ls /builds
my-project
$ git clone https://gitlab-ci-token:${CI_JOB_TOKEN}@gitlab.com/staging-fw/my_dependencies.git /builds/dependencies
Cloning into '/builds/dependencies'...
Job succeeded
One thing to note is that the first time a pipeline is created it displays:
Initialized empty Git repository
The second time a pipeline is created, the log output is as follows:
Running with gitlab-runner 12.2.0 (a987417a)
on old_gen_runner 6fsjs96e
Using Docker executor with image gcc-arm_4_7-2013q3:3.0 ...
Using docker image sha256:5d4741a428654beb44a3c004822e4d2ceededc88f22ec1ec7f45dedf707a0302 for gcc-arm_4_7-2013q3:3.0 ...
Running on runner-6fsjs96e-project-13664495-concurrent-0 via my-laptop.local...
Fetching changes with git depth set to 50...
Reinitialized existing Git repository in /builds/staging-fw/my-project/.git/
From https://gitlab.com/staging-fw/my-project
722c2c3..f321b75 master -> origin/master
Checking out f321b75f as master...
Skipping Git submodules setup
$ python /scripts/info.py
Printing job info...
Builds dir: /builds
Commit Message:
Modified yml file.
Branch: master
Project dir: /builds/staging-fw/my-project
$ ls /builds
my-project
tools
This time the log output said:
Reinitialized existing Git repository
And this time it listed two folders in the /builds directory:
$ ls /builds
staging-fw
tools
This indicates to me that the /builds directory is not created individually for each Docker container and is in fact shared between all pipelines. Is this correct? Because I can’t find any documentation on this.
Environment description
I am using gitlab-runner and Docker on my MacBook Pro running Mojave v10.14.6.
My repos are hosted on GitLab.com.
gitlab-runner:
Version: 12.2.0
Git revision: a987417a
Git branch: 12-2-stable
GO version: go1.8.7
Built: 2019-08-22T13:06:00+0000
OS/Arch: darwin/amd64
docker:
Docker version 19.03.1, build 74b1e89
Client:
Debug Mode: false
Server:
Containers: 5
Running: 0
Paused: 0
Stopped: 5
Images: 36
Server Version: 19.03.1
Storage Driver: overlay2
Backing Filesystem: extfs
Supports d_type: true
Native Overlay Diff: true
Logging Driver: json-file
Cgroup Driver: cgroupfs
Plugins:
Volume: local
Network: bridge host ipvlan macvlan null overlay
Log: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslog
Swarm: inactive
Runtimes: runc
Default Runtime: runc
Init Binary: docker-init
containerd version: 894b81a4b802e4eb2a91d1ce216b8817763c29fb
runc version: 425e105d5a03fabd737a126ad93d62a9eeede87f
init version: fec3683
Security Options:
seccomp
Profile: default
Kernel Version: 4.9.184-linuxkit
Operating System: Docker Desktop
OSType: linux
Architecture: x86_64
CPUs: 4
Total Memory: 1.952GiB
Name: docker-desktop
ID: DGZ6:2TO4:OFDJ:MTXA:DUWZ:R3ZN:KWGA:F5UJ:Z4RM:2ABB:53O5:F3RL
Docker Root Dir: /var/lib/docker
Debug Mode: true
File Descriptors: 30
Goroutines: 46
System Time: 2019-09-04T00:12:39.5088795Z
EventsListeners: 2
HTTP Proxy: gateway.docker.internal:3128
HTTPS Proxy: gateway.docker.internal:3129
Registry: https://index.docker.io/v1/
Labels:
Experimental: false
Insecure Registries:
127.0.0.0/8
Live Restore Enabled: false
Product License: Community Engine
config.toml contents
concurrent = 1
check_interval = 0
[session_server]
session_timeout = 1800
[[runners]]
name = "old_gen_runner"
url = "https://gitlab.com"
token = "6xxxxxxxxxxxxxxxxx"
executor = "docker"
[runners.custom_build_dir]
[runners.docker]
tls_verify = false
image = "gcc:5.2.0"
privileged = false
disable_entrypoint_overwrite = false
oom_kill_disable = false
disable_cache = false
volumes = ["/cache"]
shm_size = 0
pull_policy = "never"
[runners.cache]
[runners.cache.s3]
[runners.cache.gcs]
Used GitLab Runner version
gitlab-runner:
Version: 12.2.0
Git revision: a987417a
Git branch: 12-2-stable
GO version: go1.8.7
Built: 2019-08-22T13:06:00+0000
OS/Arch: darwin/amd64
Using Docker version 19.03.1, build 74b1e89 executor with custom image gcc-arm_4_7-2013q3:3.0
—>
Possible fixes
I don’t have a recommendation for a fix, I’m simply trying to understand why this is happening. If this is expected then it’s fine, I just want to understand why and how. Thank you.
Edited Sep 04, 2019 by Eddie Garcia