this folder contains files git can only clone to empty folders что делать

davisford / gist:5039064

Let’s say you start a project locally, and do some editing.

Now you decide you want to create a new github repo and track it, but the directory is non-empty so git won’t let you clone into it. You can fix this, thusly:

This comment has been minimized.

Copy link Quote reply

kyo00710 commented Oct 18, 2013

Hi I used it, but not success

After I use git remote command, It tells me that the origin is existed, and I can’t do anything like you said.

This comment has been minimized.

Copy link Quote reply

figa12 commented Nov 2, 2013

Exactly what I needed, works like a charm.

This comment has been minimized.

Copy link Quote reply

TwisterMc commented Jan 15, 2014

This helped a lot. For my repositories, I didn’t have to do get brach master origin/master or git checkout master as no branches existed. So I skipped those two steps and it worked great.

This comment has been minimized.

Copy link Quote reply

wmgodyak commented Mar 16, 2016

This comment has been minimized.

Copy link Quote reply

michael-o commented Oct 17, 2016

This comment has been minimized.

Copy link Quote reply

nanusdad commented May 31, 2017

This comment has been minimized.

Copy link Quote reply

evanlalo commented Dec 14, 2017

Works like a charm!

This comment has been minimized.

Copy link Quote reply

glinders commented Jul 23, 2018

If files that are tracked in the source location, already exist in the target directory, git will complain:

This comment has been minimized.

Copy link Quote reply

ericksuryadinata commented Oct 19, 2018

This comment has been minimized.

Copy link Quote reply

lakostin commented Dec 12, 2018

This comment has been minimized.

Copy link Quote reply

samjross commented Feb 18, 2020 •

assuming your Laravel directory is in

This comment has been minimized.

Copy link Quote reply

xniti3x commented Aug 23, 2020

assuming your Laravel directory is in

You can’t perform that action at this time.

You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.

Источник

How do I clone into a non-empty directory?

I have directory A with files matching directory B. Directory A may have other needed files. Directory B is a git repo.

I want to clone directory B to directory A but git-clone won’t allow me to since the directory is non-empty.

I can’t clone into an empty directory because I have files in directory A that are not in directory B and I want to keep them.

Is there any way to do this?

17 Answers 17

This worked for me:

this folder contains files git can only clone to empty folders что делать. Смотреть фото this folder contains files git can only clone to empty folders что делать. Смотреть картинку this folder contains files git can only clone to empty folders что делать. Картинка про this folder contains files git can only clone to empty folders что делать. Фото this folder contains files git can only clone to empty folders что делать

In the following shell commands existing-dir is a directory whose contents match the tracked files in the repo-to-clone git repository.

A slight modification to one of the answers that worked for me:

to start working on the master branch straight away.

this folder contains files git can only clone to empty folders что делать. Смотреть фото this folder contains files git can only clone to empty folders что делать. Смотреть картинку this folder contains files git can only clone to empty folders что делать. Картинка про this folder contains files git can only clone to empty folders что делать. Фото this folder contains files git can only clone to empty folders что делать

this folder contains files git can only clone to empty folders что делать. Смотреть фото this folder contains files git can only clone to empty folders что делать. Смотреть картинку this folder contains files git can only clone to empty folders что делать. Картинка про this folder contains files git can only clone to empty folders что делать. Фото this folder contains files git can only clone to empty folders что делать

I have used this a few moments ago, requires the least potentially destructive commands:

Another simple recipe seems to work well for me:

My main use case for checking out to a directory with existing files is to control my Unix dotfiles with Git. On a new account, the home directory will already have some files in it, possibly even the ones I want to get from Git.

This worked for me:

I had a similar problem with a new Apache web directory (account created with WHM) that I planned to use as a staging web server. I needed to initially clone my new project with the code base there and periodically deploy changes by pulling from repository.

The problem was that the account already contained web server files like:

. that I did not want to either delete or commit to my repository. I needed them to just stay there unstaged and untracked.

I went to my web folder (existing_folder):

Then, thanks to this article, I just added the list of those files to:

Now checking git status returns:

Now I can deploy changes to this web server by simply pulling from my git repository. Hope this helps some web developers to easily create a staging server.

Источник

How to get Git to clone into current directory

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

22 Answers 22

simply put a dot next to it

From git help clone :

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

this folder contains files git can only clone to empty folders что делать. Смотреть фото this folder contains files git can only clone to empty folders что делать. Смотреть картинку this folder contains files git can only clone to empty folders что делать. Картинка про this folder contains files git can only clone to empty folders что делать. Фото this folder contains files git can only clone to empty folders что делать

The following is probably not fully equivalent to a clone in all cases but did the trick for me:

@Andrew has answered it clearly here. But as simple as this also works even if the directory is not empty:

this folder contains files git can only clone to empty folders что делать. Смотреть фото this folder contains files git can only clone to empty folders что делать. Смотреть картинку this folder contains files git can only clone to empty folders что делать. Картинка про this folder contains files git can only clone to empty folders что делать. Фото this folder contains files git can only clone to empty folders что делать

Directory must be empty

this folder contains files git can only clone to empty folders что делать. Смотреть фото this folder contains files git can only clone to empty folders что делать. Смотреть картинку this folder contains files git can only clone to empty folders что делать. Картинка про this folder contains files git can only clone to empty folders что делать. Фото this folder contains files git can only clone to empty folders что делать

To be sure that you could clone the repo, go to any temporary directory and clone the project there:

This will clone your stuff into a project_hub directory.

Once the cloning has finished, you could move this directory wherever you want:

This is safe and doesn’t require any magical stuff around.

git version: 2.21.0

If the current directory is empty, then this will work:

this folder contains files git can only clone to empty folders что делать. Смотреть фото this folder contains files git can only clone to empty folders что делать. Смотреть картинку this folder contains files git can only clone to empty folders что делать. Картинка про this folder contains files git can only clone to empty folders что делать. Фото this folder contains files git can only clone to empty folders что делать

Credits go to: @James McLaughlin on comments below.

In addition to @StephaneDelcroix’s answer, before using:

make sure that your current dir is empty by using

this folder contains files git can only clone to empty folders что делать. Смотреть фото this folder contains files git can only clone to empty folders что делать. Смотреть картинку this folder contains files git can only clone to empty folders что делать. Картинка про this folder contains files git can only clone to empty folders что делать. Фото this folder contains files git can only clone to empty folders что делать

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

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:

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:

Источник

Git: What’s the best practice to «git clone» into an existing folder?

I have a working copy of the project, without any source control meta data. Now, I’d like to do the equivalent of git-clone into this folder, and keep my local changes.

git-clone doesn’t allow me to clone into an existing folder. What is the best practice here?

this folder contains files git can only clone to empty folders что делать. Смотреть фото this folder contains files git can only clone to empty folders что делать. Смотреть картинку this folder contains files git can only clone to empty folders что делать. Картинка про this folder contains files git can only clone to empty folders что делать. Фото this folder contains files git can only clone to empty folders что делать

18 Answers 18

If your existing directory is named «code».

This can also be done without doing a checkout during the clone command; more information can be found here.

Don’t clone, fetch instead. In the repo:

Then you can reset the tree to get the commit you want:

and you are like you cloned.

The interesting question here (and the one without answer): How to find out which commit your naked tree was based on, hence to which position to reset to.

this folder contains files git can only clone to empty folders что делать. Смотреть фото this folder contains files git can only clone to empty folders что делать. Смотреть картинку this folder contains files git can only clone to empty folders что делать. Картинка про this folder contains files git can only clone to empty folders что делать. Фото this folder contains files git can only clone to empty folders что делать

The following i did, to checkout master branch in an existing directory:

this folder contains files git can only clone to empty folders что делать. Смотреть фото this folder contains files git can only clone to empty folders что делать. Смотреть картинку this folder contains files git can only clone to empty folders что делать. Картинка про this folder contains files git can only clone to empty folders что делать. Фото this folder contains files git can only clone to empty folders что делать

Using a temp directory is fine, but this will work if you want to avoid that step. From the root of your working directory:

this folder contains files git can only clone to empty folders что делать. Смотреть фото this folder contains files git can only clone to empty folders что делать. Смотреть картинку this folder contains files git can only clone to empty folders что делать. Картинка про this folder contains files git can only clone to empty folders что делать. Фото this folder contains files git can only clone to empty folders что делать

I’d git clone to a new directory and copy the content of the existing directory to the new clone.

Lots of answers already to do it the way that the OP asked. But it worth noting that doing it the opposite way around is far simpler:

To clone a git repo into an empty existing directory do the following:

this folder contains files git can only clone to empty folders что делать. Смотреть фото this folder contains files git can only clone to empty folders что делать. Смотреть картинку this folder contains files git can only clone to empty folders что делать. Картинка про this folder contains files git can only clone to empty folders что делать. Фото this folder contains files git can only clone to empty folders что делать

this folder contains files git can only clone to empty folders что делать. Смотреть фото this folder contains files git can only clone to empty folders что делать. Смотреть картинку this folder contains files git can only clone to empty folders что делать. Картинка про this folder contains files git can only clone to empty folders что делать. Фото this folder contains files git can only clone to empty folders что делать

This is the Best of all methods i came across

Delete the temporary directory

Git thinks all files are deleted, this reverts the state of the repo to HEAD.

WARNING: any local changes to the files will be lost.

this folder contains files git can only clone to empty folders что делать. Смотреть фото this folder contains files git can only clone to empty folders что делать. Смотреть картинку this folder contains files git can only clone to empty folders что делать. Картинка про this folder contains files git can only clone to empty folders что делать. Фото this folder contains files git can only clone to empty folders что делать

There are two approaches to this. Where possible I would start with a clean folder for your new git working directory and then copy your version of things in later. This might look something like*:

On the other hand if you really must do it the other way around, you can get the same result with something like this:

Either way, the first thing I would do is run something like git stash to get a copy of all your local changes set aside, then you can re-apply them and work through which ones you want to get committed.

* Both examples assume you start out on the shell in the parent directory of your project.

Источник

How to clone only some directories from a git repository?

For example, I want to download PCL 3d_rec_framework.

How can I download this directory?

I tried this, but it didn’t work:

I don’t want to download git of PCL and remove all other directories that I don’t want.

How do I download just a single directory?

this folder contains files git can only clone to empty folders что делать. Смотреть фото this folder contains files git can only clone to empty folders что делать. Смотреть картинку this folder contains files git can only clone to empty folders что делать. Картинка про this folder contains files git can only clone to empty folders что делать. Фото this folder contains files git can only clone to empty folders что делать

8 Answers 8

dobey’s answer is no longer the case since git v1.7. You can now checkout certain folders from a repository. The full instructions are found here.

This tells git which directories you want to checkout. Then you can pull just those directories

First, do:

Then:

. And lastly:

this folder contains files git can only clone to empty folders что делать. Смотреть фото this folder contains files git can only clone to empty folders что делать. Смотреть картинку this folder contains files git can only clone to empty folders что делать. Картинка про this folder contains files git can only clone to empty folders что делать. Фото this folder contains files git can only clone to empty folders что делать

This option was added together with an update to the remote protocol, and it truly prevents objects from being downloaded from the server.

E.g., to clone only objects required for d1 of this minimal test repository: https://github.com/cirosantilli/test-git-partial-clone I can do:

That repository contains:

All contents are pseudo-random and therefore incompressible.

Clone times on my 36.4 Mbps internet:

The sparse-checkout part is also needed unfortunately. You can also only download certain files with the much more understandable:

but that method for some reason downloads files one by one very slowly, making it unusable unless you have very few files in the directory.

Analysis of the objects in the minimal repository

The clone command obtains only:

Then, the git sparse-checkout set command fetches only the missing blobs (files) from the server:

Even better, later on GitHub will likely start supporting:

I observed which objects were fetched with:

git sparse-checkout

I think this command is meant to manage a settings file that says «I only care about these subtrees» so that future commands will only affect those subtrees. But it is a bit hard to be sure because the current documentation is a bit. sparse 😉

It does not, by itself, prevent the fetching of blobs.

When I tried on Git 2.25.1:

it didn’t work because the init actually fetched all objects.

However, in Git 2.28 it didn’t fetch the objects as desired. But then if I do:

Keep an eye out for the partial clone feature to become generally available[1].

[1]: GitHub is still evaluating this feature internally while it’s enabled on a select few repositories (including the example used in this post). As the feature stabilizes and matures, we’ll keep you updated with its progress.

So yeah, it’s just too hard to be certain at the moment, thanks in part to the joys of GitHub being closed source. But let’s keep an eye on it.

Command breakdown

The server should be configured with:

—filter=blob:none skips all blobs, but still fetches all tree objects

Test it out locally

The following script reproducibly generates the https://github.com/cirosantilli/test-git-partial-clone repository locally, does a local clone, and observes what was cloned:

Output in Git v2.19.0:

I have a dream

This feature could revolutionize Git.

Imagine if GitHub would allow per file / directory metadata like stars and permissions, so you can store all your personal stuff under a single repo.

Источник

Добавить комментарий

Ваш адрес email не будет опубликован. Обязательные поля помечены *