meta data for this page
  •  

This is an old revision of the document!


Merge repos into one

subtree add

Adding remote repos as subtrees results in merges in history, which cannot be rebased to get flat history. Rebasing causes to subtree appear in main repo root directory instead of subdirectory. Better use next method with moving files manually.

git remote add my-subtree /path/to/subtree.git
git subtree add --prefix=vendor/ my-subtree master
# with squashed commits # git subtree add --squash --prefix=vendor/ my-subtree master
# cleanup # git rebase my-subtree/master

Merge another repo (RRR) into directory of repo (LLL)

Idea is to fetch remote repo RRR into local repo LLL Then modify file location of repo BBB to be in desired path and merge it into repo LLL.

git remote add RRR http://URI_to_RRR_repo
git fetch RRR
git checkout -b branch_change_file_location RRR/master
 
# now move files from remote repo RRR into correct path:
mkdir app_RRR
git mv src app_RRR/src
git commit -m "location of app_RRR adapted to local repo"
 
# switch to LLL repo 
git checkout master                
# merge previously created branch "LLL/branch_change_file_location" into "LLL/master"
git merge branch_change_file_location
git commit
 
# cleanup
git remote rm RRR
git branch -d branch_change_file_location
 
# optionally:
git rebase
# push merged master
git push                           

Split dirs into separate repos

git filter tools

Detach(move) subdirectory into separate Git repository

http://stackoverflow.com/questions/359424/detachmove-subdirectory-into-separate-git-repository

# Split dir form repo
pushd <big-repo>
git subtree split -P <name-of-folder> -b <name-of-new-branch>
popd
 
# Create new repo
mkdir <new-repo>
pushd <new-repo>
 
git init
git pull </path/to/big-repo> <name-of-new-branch>
 
# Link the new repo to Github or wherever
 
git remote add origin <git@github.com:my-user/new-repo.git>
git push origin -u master
 
#Cleanup, if desired
 
popd # get out of <new-repo>
pushd <big-repo>
 
git rm -rf <name-of-folder>