Skip to content

Instantly share code, notes, and snippets.

@tekkub
Created August 4, 2009 00:30
Show Gist options
  • Select an option

  • Save tekkub/160946 to your computer and use it in GitHub Desktop.

Select an option

Save tekkub/160946 to your computer and use it in GitHub Desktop.

Revisions

  1. tekkub created this gist Aug 4, 2009.
    32 changes: 32 additions & 0 deletions subtree_merge.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,32 @@
    #! /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