Dmitriy
Dmitriy

Reputation: 683

Git: move part from one repo to other repo with history

I have two git repositories: repo1 and repo2. repo1 contains folders "dir_a", "dir_b" and other. How I can transfer all files including git history from dir_a and dir_b of repo1 to repo2?

I've found some helpful article for such task: http://gbayer.com/development/moving-files-from-one-git-repository-to-another-preserving-history. However, it is not fully suitable for me because I need to transfer 2 directories.

Upvotes: 0

Views: 775

Answers (1)

CodeWizard
CodeWizard

Reputation: 141956

How I can transfer all files including git history from dir_a and dir_b of repo1 to repo2?

You can use git filter-branch and or git subtree split

Sample code:

filter-branch

# Filter the master branch to your directory and remove empty commits
git filter-branch --prune-empty --subdirectory-filter YOUR_FOLDER_NAME filter_from_branch

This will checkout all your desired files from the given folder to the current directory


subtree split

git subtree git-subtree - Merge subtrees together or split repository into subtrees

git subtree split -P <name-of-folder> -b <name-of-new-branch>

enter image description here

Upvotes: 1

Related Questions