5

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.

Community
  • 1
  • 1
Sasi
  • 1,666
  • 2
  • 24
  • 44
  • 1
    What do you expect as a result of moving a repo into another *non-empty* repo? – Amadan Feb 06 '17 at 06:46
  • My Repo B already has Proj1 and Proj2. Now I want RepoA to be moved as Proj3 into RepoB with all commit history from RepoA. – Sasi Feb 06 '17 at 07:11

1 Answers1

5
  • 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.

Sajib Khan
  • 22,878
  • 9
  • 63
  • 73