Skip to content

Instantly share code, notes, and snippets.

@tekkub
Created August 4, 2009 00:30
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tekkub/160946 to your computer and use it in GitHub Desktop.
Save tekkub/160946 to your computer and use it in GitHub Desktop.
Subtree merge
#! /bin/bash
# Based off of http://www.kernel.org/pub/software/scm/git/docs/howto/using-merge-subtree.html
if [[ ! "$2" || ("$3" && ! "$4" ) ]]
then
filename=`echo "$0"| sed "s/.*\///"`
echo "Usage: $filename remote_name repo_url branch_name path_to_merge_to"
echo " * Create a new subtree merge"
echo " $filename remote_name branch_name"
echo " * Pull from remote_name/branch_name into subtree"
exit 0
fi
if [ "$3" ]
then # Create our subtree
echo "Creating new subtree merge"
name=$1
url=$2
branch=$3
path=$4
git remote add -f $name $url
git merge -s ours --no-commit $name/$branch
git read-tree --prefix=$path -u $name/$branch
git commit -m "Subtree-merge $url branch '$branch' to $path"
else # Pull!
echo "Performing subtree pull"
name=$1
branch=$2
git pull -s subtree $name $branch
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment