Skip to content

Instantly share code, notes, and snippets.

@elazar
Created May 1, 2012 18:53
Show Gist options
  • Save elazar/2570462 to your computer and use it in GitHub Desktop.
Save elazar/2570462 to your computer and use it in GitHub Desktop.
git mem/rec bash aliases
; These aliases are only useful if you work from a directory containing multiple repos.
; mem stores the current branch or commit checked out per repo to a specified file.
; rec reads a specified file in this format and restores the repos to their respective branches or commits.
; This is useful if you're working on or testing multiple branches together and/or simultaneously.
;
; Example:
; git mem /path/to/file
; [change repo configurations, do work, etc.]
; git rec /path/to/file
; [repos are now back in the configuration they were in when git mem was run]
[alias]
mem = "!sh -c 'for repo in *; do cd $repo; commit=$(git branch --no-color | sed -e \"/^[^*]/d\" -e \"s/^* //\"); if [ \"$commit\" = \"(no branch)\" ]; then commit=$(git rev-list --max-count=1 HEAD); fi; echo \"$repo $commit\"; cd ..; done > $1' -"
rec = "!sh -c 'cat $1 | while read repo commit; do cd $repo; git checkout $commit 2>&1 1>/dev/null; cd ..; done' -"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment