0

I want to clone a github project in Google Colab and work on some notebooks of the project. The notebook usually assume that they run in the folder corresponding to the content of the project. So, wrapping the project in another name (the project name) may mess the import section.

Anyways, it's what I tried:

!rm -r sample_data/
!git clone https://github.com/n-waves/multifit.git .

However it raise the following error:

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

However, I see nothing in the content folder (the working directory of colab). So, I don't know how to solve this problem.

Update: apparently there is a .config directory there, which is hidden. I removed the config directory via !rm -r .config/ and now the clone was performed. However, it's not a nice solution because the config folder might be needed by the Google.

I also tried a similar question by How do I clone into a non-empty directory?

!git init
!git remote add origin https://github.com/n-waves/multifit.git
!git fetch
!git reset origin/master  # Required when the versioned files existed in path before "git init" of this repo.
!git checkout -t origin/master

But it gives the error:

fatal: A branch named 'master' already exists.
Ahmad
  • 8,811
  • 11
  • 76
  • 141
  • If you remove the `.`, does that work? I think you're telling it to create the current directory... – underscore_d Jun 12 '20 at 13:33
  • Agree with @underscore_d the fullstop means you are saying to git "create current directory" – mike Jun 12 '20 at 13:36
  • @underscore_d If I remove the `.` it clone the project but put it in a folder named with that project, I don't want that. I've just read that using `.` must copy the content into the directory provided that the directory is empty – Ahmad Jun 12 '20 at 13:38
  • Well, then, it mustn't _really_ be empty. Are you sure you have hidden/system files visible and there are none of those? – underscore_d Jun 12 '20 at 13:39
  • @underscore_d it doesn't show anything. However, it may have some hidden files I suspect a `.config` directory is there – Ahmad Jun 12 '20 at 13:40
  • @underscore_d I removed the config directory via `!rm -r .config/` and now the clone was performed. However, it's not a nice solution because the `config` folder might be needed by the Google – Ahmad Jun 12 '20 at 13:45
  • You could just clone into some random temp folder, and then cut/paste the resulting `.git` directory to where you really want it to go. – underscore_d Jun 12 '20 at 13:47
  • Does this answer your question? [How do I clone into a non-empty directory?](https://stackoverflow.com/questions/2411031/how-do-i-clone-into-a-non-empty-directory) – underscore_d Jun 12 '20 at 13:47
  • @underscore_d I remember I tried that solution (or similar) but then google couldn't find the github project. – Ahmad Jun 12 '20 at 13:49
  • @underscore_d it says `fatal: A branch named 'master' already exists.` – Ahmad Jun 12 '20 at 13:56

1 Answers1

0

If you want to use the content without additional project folder, you can use degit

!npx degit n-waves/multifit -f

Here the -f option force the content into the current directory, even if it's not empty.

Now you can import multifit easily

import multifit

No need to %cd multifit

korakot
  • 37,818
  • 16
  • 123
  • 144