0

I am trying to copy all the files in a public git repository, let's call it repo_A, into a completely new private git repository, let's call it repo_B.
As far as I know, git init --template will not fit that need. I currently run this set of terminal commands:

git clone repo_A_clone_link  
git clone repo_B_clone_link
cp -a ./repo_B/.git/. ./repo_A/.git/  
cp -a ./repo_A/. ./repo_B/   
cd ./repo_B 
git push

The push is successful, and I see all the files from repo_A in repo_B's master branch.
The problem is for some reason, I still see repo_A's commit history in repo_B.

I tried to read about the subject and investigate, but according to this question it seems that the fact repo_B's .git directory did not change should mean its history won't change either.

Also went through this question, that one and several others.

What am I missing here? How can I prevent the history from being copied as well?
I saw that using --depth 1 might solve it, but I would love to understand what I'm missing from the .git directory perspective.
Thanks!

georgek24
  • 521
  • 1
  • 4
  • 7
  • Why `cp -a ./repo_A/.`... etc.? Why not just `cp -a ./repo_A`...? or even `cp -a repo_A`... – gmatht Jun 11 '20 at 14:20
  • I don't see what went wrong but you could also try something like `git clone repo_A_clone_link; cd repo_A; rm -f .git; git clone --bare repo_B_clone_link` and then edit `bare = true` into `bare = false` in `.git/config`. – gmatht Jun 11 '20 at 14:26

1 Answers1

0

In this case, you did copy the .git directory with cp -a, which operates recursively. The .git directory contains all the history and objects in the repository, and if you copy it from one repository to another, all of the history will be copied as well.

If you want to just copy the tracked files, you can use something like this:

(cd repoA && git archive --format=tar HEAD) | (cd repoB && tar -xvf -)
bk2204
  • 64,793
  • 6
  • 84
  • 100
  • Apologies for the delayed response. I'm actually overwriting the .git directory in the first repo before running `cp -a`, so as far as I'm aware that should be good. – georgek24 Jun 15 '20 at 06:57
  • You're not replacing it, so there are still objects, packs, and references you're not overwriting. If you want to replace it entirely, then remove the existing directory first. – bk2204 Jun 15 '20 at 22:54