How to use git clone to set up the repo without downloading files?

3.6k Views Asked by At

To manage yarn workspaces I am copying the pertinent subfolders into temporary folders and push them into their respective git repositories

To setup these repositories I am using git clone, which downloads everything and sets up the origin and remote configuration (and then copy files)

Can I skip the downloading of the repo folders?

Would this work?

git clone --filter=blob:none --no-checkout <repo>

EDIT

The usual way would be (as said by @edd34 and @pallgeuer below) with git init and remote add origin, but with the git clone above is only one line

-> what are the differences? What is achieved with this approach? And if incorrect, is there any way to get the same (provided a remote already exists) with git clone?

2

There are 2 best solutions below

0
Paolo On BEST ANSWER

The command:

$ git clone --no-checkout <repo> $(pwd)

will correctly clone only the .git folder, and no files, in the current working directory.

This should be equivalent to the more standard workflow:

$ git init
$ git remote add origin <url>
$ git fetch origin

You end up with the .git folder in your working directory and don't perform the HEAD checkout.

1
edd34 On

here how you can do it :

  1. Create a git repository inside an empty repository :

git init

  1. Add your remote repository :

git remote add origin <url_repo>

  1. Perform a fetch to update your local repository :

git fetch

  1. You can also checkout a specific folder/file :

git checkout -- <relative_path_to_folder_or_file_to_checkout>