简体   繁体   中英

How to clone a Github project in Google Colab without the container folder

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM