Skip to content

Instantly share code, notes, and snippets.

@artyom
Last active March 29, 2016 11:58
Show Gist options
  • Select an option

  • Save artyom/d876e1c179627064e782 to your computer and use it in GitHub Desktop.

Select an option

Save artyom/d876e1c179627064e782 to your computer and use it in GitHub Desktop.
Manage dependencies with git subtrees
#!/bin/sh -eu
deps () {
# format is "key path repo branch"
cat <<-"EOF"
dep1 libs/dep1 git@github.com:User/lib1.git master
EOF
}
SEL=${1:-}
BR=${2:-}
deps | while read key path repo branch ; do
test -n "$SEL" && test "$SEL" != "$key" && continue
test -n "$BR" && branch=$BR
git subtree pull --squash --prefix=$path $repo $branch
done
@artyom

artyom commented Mar 29, 2016

Copy link
Copy Markdown
Author

It can be called in tree different ways:

  1. without parameters at all to pull updates to every dependency
    (hard-coded in this script) to their latest versions or branch specified in deps function;
  2. with a single parameter to pull updates to given dependency (argument
    is short "name" of dependency hard-coded in this script) from its remote
    branch hard-coded in deps function;
  3. with two arguments: first being the short "name" of dependency as in
    in previous case, and the second being specific branch name.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment