Sasi M Sasi M - 4 years ago 75
Git Question

Move Git repo A into Git repo B (Not empty) with complete history

I want to move all my files from Git Repo A to Git Repo B with complete history. Git B already contains another project files. I tried several ways such as

How to move files from one git repo to another (not a clone), preserving history

How to move files from one git repo to another preserving history using `git format-patch`and `git am`

I tried executing all the commits via terminal. But I am getting

"git filter-branch fatal:myDirectory/: 'myDirectory' is outside repository Could not get the commits"
while executing
git filter-branch --subdirectory-filter muDirectory -- --all
.

I need detailed guidance with step by step procedure to move all files from one repo to another. Would appreciate any help, Thanks in advance.

Answer Source
  • Go into repoB and add a new remote with repoA URL (say, repoA).
  • Checkout new branch (say, branchA) with repoA/master history.
  • Git move all folder/file into a new sub-directory RepoA. Command git mv <src> <dest>.
  • Commit your changes in branchA.
  • Checkout master branch and merge branchA branch.

Follow the commands:

# go into repoB master branch
$ git remote add repoA <repoA-url>
$ git remote -v                     # confirm repoA is added named 'repoA'

$ git fetch repoA
$ git checkout -b branchA repoA/master
$ git mv <folder/file> repoA/<folder/file>     # repeat untill all files/folders are moved
$ git commit -am 'Moved repoA folder/file into repoA dir' 


$ git checkout master
$ git merge branchA

$ git add .
$ git commit -m 'Added repoA into repoA directory'
$ git push origin master

Git Subtree: You can do this using git subtree also:

$ git subtree add --prefix=repoA/ <repoA-url> master

Pull master branch of repoA into a sub-directory named repoA.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download