Skip to content

Instantly share code, notes, and snippets.

@jtyr
Last active April 27, 2016 11:30
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 jtyr/7250a08a6ac628123fb3 to your computer and use it in GitHub Desktop.
Save jtyr/7250a08a6ac628123fb3 to your computer and use it in GitHub Desktop.
Bundle and unbundle local Git repos
###
#
# This Makefile helps to bundle and unbundle local Git repos. Directories
# containing bare repos should end with `.git` (e.g. `mybarerepo.git`).
#
###
DIRS = $(shell find . -type d -maxdepth 1)
BUNDLES = $(filter-out $(wildcard *.git.bundle), $(wildcard *.bundle))
BUNDLES_BARE = $(wildcard *.git.bundle)
.PHONY: all export import
all:
@echo "Usage: make [export|import]"
bundle: export
export:
@$(foreach DIR, $(DIRS), \
echo "### Bundling $(DIR):"; \
git -C $(DIR) bundle create ../$(DIR).bundle --all; \
echo; \
)
unbundle: import
import:
@$(foreach B, $(BUNDLES), \
echo "### Unbundling $(B):"; \
test -e $(B:.bundle=) && \
echo "Repo already exists" || \
( \
git clone $(B) && \
cd $(B:.bundle=) && \
for i in $$(git branch -r | egrep -v "(HEAD|master)"); do \
git branch --track $${i#*/} $i; \
done \
); \
echo; \
)
@$(foreach B, $(BUNDLES_BARE), \
echo "### Unbundling $(B):"; \
test -e $(B:.bundle=) && \
echo "Repo already exists" || \
git clone --bare $(B) $(B:.bundle=); \
echo; \
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment