2

How to copy one repo entirely to another repo with history.

I don't want to use fork or mirroring options, I tried out branch-filter options but it is limited to one directory. git filter-branch --subdirectory-filter /../RepoA/dire1

I was referring below url https://medium.com/@ayushya/move-directory-from-one-repository-to-another-preserving-git-history-d210fa049d4b/

Example:
Source      Target             Requirement
------      ----              -------------------
RepoA       RepoB(new Repo)   Copy entire history  
  - Dir1     - Dir1
  - Dir2     - Dir2

Could you please suggest?

phd
  • 82,685
  • 13
  • 120
  • 165
echo
  • 23
  • 1
  • 4
  • Could something here help? https://stackoverflow.com/search?q=%5Bgit%5D+combine+multiple+repositories – phd Jun 11 '20 at 09:41
  • `submodule` or `subtree`? I'm not sure what is your question. Maybe It would be better if you explain why or what you are trying to achieve. – Marek R Jun 12 '20 at 10:28
  • Hi was below answer helpful to you? how did it go with above case? – Levi Lu-MSFT Jun 15 '20 at 09:55

1 Answers1

2

You can try using the --index-filter instead of the --subdirectory-filter.

$ git filter-branch --index-filter \
    'git ls-files -s | sed "s#\t#&RepoA/#" |
     GIT_INDEX_FILE=$GIT_INDEX_FILE.new \
     git update-index --index-info &&
     mv $GIT_INDEX_FILE.new $GIT_INDEX_FILE' HEAD

Please checkout this thread for more information.

If RepoB is a fresh new repo. Yon can also try below commands. Clone RepoA to local machine, remove the remote origin of RepoA, then add the remote url to RepoB. see below example:

git clone http:/url/repoA
cd repoA
git pull origin branchName
git remote remove origin
git remote add origin http:/url/repoB
git push -u origin --all

You can also try using git submodule. Check the git document for more information.

Levi Lu-MSFT
  • 27,483
  • 2
  • 31
  • 43