Created
December 15, 2013 13:48
-
-
Save krlmlr/7973278 to your computer and use it in GitHub Desktop.
Managing contents of another "sub" repo inside a "main" repo using `git subtree`
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/main | |
/sub | |
/.main | |
/.sub |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
set -e | |
DIR=$PWD | |
commits() { | |
repo=$1 | |
shift | |
for f in $@; do | |
touch $f | |
git add $f | |
git commit -m "added $f for $repo" | |
done | |
git push -u origin master | |
} | |
show() { | |
ls -R | |
read -p "show: Press Return." anything | |
} | |
sync() { | |
cd main | |
git subtree pull --prefix sub sub master -m "Merging from sub" | |
git subtree push --prefix sub sub master -m "Merging to sub" | |
cd .. | |
#read -p "sync: Press Return." anything | |
} | |
# Init two repositories "main" and "sub", add a corresponding --bare repository | |
# as origin | |
for r in main sub; do | |
rm -rf $r .$r | |
git init --bare .$r | |
git init $r | |
cd $r | |
git remote add origin $DIR/.$r | |
cd .. | |
done | |
# Populate with some independent commits | |
cd main | |
commits main a b c | |
cd .. | |
cd sub | |
commits sub d e f | |
cd .. | |
# Add "sub" repository as subdir to "main" repository | |
cd main | |
git remote add sub $DIR/.sub | |
git fetch --all | |
git branch sub sub/master | |
git subtree add --prefix sub sub | |
git subtree pull --prefix sub sub master | |
git subtree push --prefix sub sub master | |
git push | |
cd .. | |
show | |
# Add somme commits to "sub", push | |
cd sub | |
commits sub g h i | |
cd .. | |
# Pull the newly added commits into "main/sub" | |
sync | |
show | |
# Add somme commits to "main/sub", push | |
cd main/sub | |
commits main/sub j k l | |
cd ../.. | |
# Push the newly added commits to "sub" | |
sync | |
cd sub | |
git pull | |
cd .. | |
show |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment