0

How do I move files and history from one git repo to another?

I have a private git repo with some files that I would now like to put in a public, unrelated git repo, retaining their history.

Mark Harrison
  • 297,451
  • 125
  • 333
  • 465
  • 1
    What do you want the new repo to look like? You won't be able to merge the two histories completely without rewriting all commits of the new repo (starting from the time of the oldest commit in the old repo)... – jtbandes Aug 23 '15 at 00:29
  • I just want the files added to the pubic repo. – Mark Harrison Aug 23 '15 at 00:40
  • How about `cp -R src .; git add -A; git commit`? – jtbandes Aug 23 '15 at 00:42
  • possible duplicate of [How to move a file from one git repository to another while preserving history](http://stackoverflow.com/questions/10524578/how-to-move-a-file-from-one-git-repository-to-another-while-preserving-history) – Maximillian Laumeister Aug 23 '15 at 00:55
  • @jtbandes, sure, but that misses the part I bolded in the question... how to carry the file history along. – Mark Harrison Aug 23 '15 at 01:01
  • possible duplicate of [How to move files from one git repo to another (not a clone), preserving history](http://stackoverflow.com/questions/1365541/how-to-move-files-from-one-git-repo-to-another-not-a-clone-preserving-history) – jtbandes Aug 23 '15 at 01:03
  • My remark above was incorrect. As long as you're able to get the commits into the repo, you actually can just merge them in with your master branch; you'll have two starting points but one `master`. – jtbandes Aug 23 '15 at 01:06

1 Answers1

1

To sync another repo with files and history from your local repository you may add the other repo as a new remote and push all changes.

git remote add anotherrepo <url to another repo>
git push anotherrepo master

This will push local master to the other repo, you may need to change this if you have other names for your branches.

joran
  • 2,815
  • 16
  • 18