user3715648
user3715648

Reputation: 1588

Is it possible to clone a git repo without the .git folder, into an existing non empty directory

I have an odd use case, and am not very familiar with Git. I have two git repos; repo one which is empty, and repo two which has files. I also have a folder ./foo. I want something similar to this:

cd ./foo
git clone repo_one .
git clone repo_two . (I just want the files from repo_two. No .git folder or anything)
git add --a
git push repo_one

or maybe

cd ./foo
git clone repo_two .
rm ./.git
git clone repo_one . (possible in an existing directory though?)

Are either of these possible? All I really care about is the end result; that .foo is linked to repo_one, but contains the files from repo_two.

Upvotes: 0

Views: 439

Answers (3)

Yazeed Sabri
Yazeed Sabri

Reputation: 355

Check this helpful blog post about the bundle and archive in general: https://www.perforce.com/blog/git-beyond-basics-bundle-and-archive

Upvotes: 0

Aditya
Aditya

Reputation: 1723

Since you've cloned both the Git repos, execute the following command on repo #2 to export (or archive) it without its .git folder:

git archive master | tar -x -C /path/inside/repo1

The final sequence of events would be something like this:

cd foo
git clone repo_one
git clone repo_two
cd repo_two
git archive master | tar -x -C ../repo_1

Upvotes: 1

Stefan Moch
Stefan Moch

Reputation: 101

git clone has an option --separate-git-dir= which puts the .git directory somewhere else, but it creates a file named .git in the checkout directory, which references the relocated .git-directory.

https://git-scm.com/docs/git-clone#git-clone---separate-git-dirltgitdirgt

Upvotes: 0

Related Questions