Skip to content

Instantly share code, notes, and snippets.

@rcackermanCC
Last active September 12, 2016 18:57
Show Gist options
  • Select an option

  • Save rcackermanCC/a53843829976e00230d5 to your computer and use it in GitHub Desktop.

Select an option

Save rcackermanCC/a53843829976e00230d5 to your computer and use it in GitHub Desktop.
Combining pieces of other repos

Assuming NewA and OldB:

Prep NewA

cd NewA
mkdir NewA
mv *.* NewA/
gc -m "Prep for new repo"
cd ..

Prep NewB:

cd NewB
mkdir NewB
mv *.* NewB/
gc -m "Prep for new repo"
cd ..

At this point create a new umbrella directory, and copy everything into it.

mdkir UmbrellaDir
cd UmbrellaDir

mv ../NewA ./
mv ../NewB ./

git init
git pull NewA
rm -rf NewA/.git/
rm -rf NewA/NewA/

git pull NewB
rm -rf NewB/.git/
rm -rf NewB/NewB/

For if you just want to merge a repo whole-cloth into another.

We'll merge RepoB into RepoA.

cd RepoA # RepoA is already a repo with history
git remote add RepoB <url>
git merge -s ours --no-commit --allow-unrelated-histories RepoB/master
git read-tree --prefix=RepoB -u RepoB/master

From https://help.github.com/articles/about-git-subtree-merges/.

git clone --no-hardlinks OriginalA/ NewA/
cd NewA

For each branch you want

gco <branch>
# mv .gitignore FolderIWant/.gitignore
git filter-branch --subdirectory-filter FolderIWant HEAD
git for-each-ref --format="%(refname)" refs/original/ | xargs -n 1 git update-ref -d
git reflog expire --expire=now --all
git reset --hard
git gc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment