Skip to content

Instantly share code, notes, and snippets.

@jennings
Last active December 17, 2015 23:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jennings/5692976 to your computer and use it in GitHub Desktop.
Save jennings/5692976 to your computer and use it in GitHub Desktop.
Tools I'm using to join a few unrelated repositories into one
#!/bin/sh
# Combines together unrelated branches into the current commit.
#
# Usage: combine-unrelated-branches.sh <merge-head>+
#
# combine-unrelated-branches.sh repo1/stuff repo2/stuff
NEW_TREE=$(mktemp -t $(basename $0))
FIRST_HEAD=$1
shift
# Create the merge commit
git merge -s ours --no-commit $FIRST_HEAD $*
# Combine trees from each head
for branch in $FIRST_HEAD $*; do
git ls-tree $branch >> $NEW_TREE
done
# Read the new tree into the index
git read-tree $(git mktree < $NEW_TREE)
# Commit the merged tree
git commit -m "Merging: $FIRST_HEAD $*"
rm $NEW_TREE
#!/bin/sh
# Filters a git branch by moving the entire tree into a subdirectory.
# It uses --index-filter; as a result it is very quick but happens to
# be very dumb and will move files like .gitignore and .gitattributes
# into the subdirectory as well.
#
# Usage: git-new-subdirectory-filter.sh <subdirName> <branch>
#
# git-new-subdirectory-filter.sh MySubdirName master..mybranch
# git-new-subdirectory-filter.sh MySubdirName --all
SUBDIR=$1
BRANCHES=$2
git filter-branch -f --prune-empty --index-filter '
CURRENT_INDEX=$(git write-tree);
NEW_TREE_SHA=$(echo "040000 tree $CURRENT_INDEX\t'$SUBDIR'" | git mktree);
git read-tree $NEW_TREE_SHA;
' -- $BRANCHES
#!/bin/sh
# Converts all tags into branches of the form releases/tag-name
git fetch --all --tags
for tag in $(git tag); do
git branch -f refs/releases/$tag $tag
git tag -d $tag
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment