简体   繁体   中英

Copying one git repo to another repo with history

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM