Skip to content

Instantly share code, notes, and snippets.

@nverinaud
Created September 12, 2012 11:33
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nverinaud/3706079 to your computer and use it in GitHub Desktop.
Save nverinaud/3706079 to your computer and use it in GitHub Desktop.
Git workflow: project with libraries
# Add a library
$ git remote add -f lib/[libname] [lib-remote-URL] # Add the lib remote and fetch
$ git read-tree --prefix=lib/[libname]/ -u lib/[libname]/master # Import the library files
$ git commit -m "Add [libname] library." # Commit the added library
$ git push # We're done !
# Update to the latest version of a library
$ git pull -s subtree --squash --no-commit lib/[libname] master # Update files of the library
$ git commit -m "Update [libname] library." # Commit the update in master
$ git push # We're done !
# Useful aliases
[Alias]
lib-remote-add = "!f() { git remote add -f lib/$1 $2; }; f" # Add and fetch a remote
lib-import = "!f() { git read-tree --prefix=lib/$1 -u lib/$1/master; }; f" # Import files from the remote (you must call lib-remote-add before)
lib-add = "!f() { git lib-remote-add $1 $2 && git lib-import $1 && git commit -m \"Add $1 library.\"; }; f" # Combine lib-remote-add and lib-import and commit changes automatically
lib-update = "!f() { git pull -s subtree --squash --no-commit lib/$1 master && git commit -m \"Update $1 library.\"; }; f" # Update the specified lib and commit the update automatically
# Add a library with above aliases
$ git lib-add [libname] [lib-remote-URL]
# Update to the latest version of a library with above aliases
$ git lib-update [libname]
@nverinaud
Copy link
Author

Thanks to Jefromi for his help on git alias.

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