Skip to content

Instantly share code, notes, and snippets.

@tommcdo
Last active December 28, 2015 05:49
Show Gist options
  • Save tommcdo/7452617 to your computer and use it in GitHub Desktop.
Save tommcdo/7452617 to your computer and use it in GitHub Desktop.

Say you're checked out on a feature branch, feature/foo. You realize that the feature you're implementing has a dependency that isn't really in the scope of what the feature does; it just needs that. It would be useful for that to exist on develop, too. From your feature branch feature/foo, run the command

git dependency create bar

This will find the common ancestor between, by default, develop and feature/foo. From there it will create a new branch called dependency/bar, and switch to it. There you can implement your dependency and make some commits. When you're done, switch back to your feature branch, then run

git dependency merge bar

This will merge dependency/bar into, by default, develop and feature/foo. It will leave you checked out on feature/foo after it's done.

#!/bin/bash
action=$1
shift
name=$1
shift
branch="dependency/$name"
parent=$1
shift
if [ -z "$parent" ]; then
parent=develop
fi
me=$1
shift
if [ -z "$me" ]; then
# Get the current branch
me=$(git rev-parse --abbrev-ref HEAD)
fi
case "$action" in
create)
ancestor=$(git merge-base $me $parent)
git branch $branch $ancestor
git checkout $branch
;;
merge)
git checkout $parent
git merge $branch
git checkout $me
git merge $branch
;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment