Git rambo

I'm not a developer but it doesn't mean I don't use git daily. I deal with a lot of repositories actually, and I wanted something to reduce the number of fetch/pull that I do in a day so I built a little script.

git_sync () {
  # all arguments should be repository path
  echo -e "\nrepo" "${@}"
  git -C "${@}" fetch --all --prune --quiet
  git -C "${@}" pull --all --rebase --autostash
}; export -f git_sync

git_loop() {
  while IFS= read -r -d '' GIT_DIR; do
    echo "${GIT_DIR%/*}"
  done < <(find .\
            -name "*.git" \
            -type d -print0) | parallel -I% -j 8 --max-args 1 -- git_sync %
}; git_loop

You can save that as an executable script in a directory present in your $PATH. I named mine git-rambo.

Then in .gitconfig:

  rambo = !git-rambo

And that's it. Now you can do git rambo !

The principle of the script is to find all folders with a .git folder in it, go there and do some git synchronizations.

The Rambo thing is because it uses rebase and can potentially mess with the current workspace of repositories. Using this script should be done over sane local repositories. In case of unsaved work, (aka code un-commited in the workspace), then it'll autostash the workspace, apply the potential distant changes and pop the stack off. If some conflicts appear, it'll be a more complex situation to deal with though.


I could also have named that git flash, thanks to parallel but I liked the silly rambo name more.

Also, note that it can run inside one repository and will then act as a shortcut to what's in the git_sync shell function.

Julien Pericat
Linux Sysadmin, SysOps & DevOps friendly

Happily automating and putting things in containers.