Reputation: 11
I have just copied a directory to another local git repo. It turns out that directory I copied is also another git repo, so now I have what I assume is called a nested repo.
I wanted to keep the outer repo and then to integrate the inner repo as the outer repo (modifying the remote origin, per say). One of my concern is because the inner repo has several branches. There is only one branch among them that I wanted to keep.
I am quite confused with what's the best practice to solve this issue. Hope someone can give me some pointers for this. Thanks!
Upvotes: 1
Views: 1870
Reputation: 25592
You can use git subtree
to import files from a second repository while keeping their history.
git status
). If you've already tried to manually copy files in, delete them. Git will copy them for you.cd
to the top level of your repository.git subtree add --prefix=inner path/to/other/repo some-branch
. This creates an inner
subdirectory and puts the contents of the other repo's some-branch
in it.git log
shows the history of the imported files.Upvotes: 0
Reputation: 15622
You can only keep the files, not the history.
.git
folder and any .git*
file from the destination folder.In the git shell
do this:
/other/location/otherPrepo>git checkout the-branch-wanted
/other/location/otherPrepo>cp -R * -R /target/location/targetRepo/targetFolder/
/other/location/otherPrepo>rm -rf /target/location/targetRepo/targetFolder/.git*
/other/location/otherPrepo>cd /target/location/targetRepo/
/target/location/targetRepo/>git add targetFolder
/target/location/targetRepo/>git commit -m "added files from otherPrepo"
[edit:] don't forget the checkin...
Upvotes: 1