Skip to content

Instantly share code, notes, and snippets.

@smarek
Created January 10, 2018 09:52
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 smarek/e71cfb7028ada8ad9c3b6af9e1023a2e to your computer and use it in GitHub Desktop.
Save smarek/e71cfb7028ada8ad9c3b6af9e1023a2e to your computer and use it in GitHub Desktop.
Update all git repositories in subfolders (worktree max 2-levels deep)
#!/bin/bash
# run like git_update_dir.sh /my/long/folder/path/.git
GIT_PATH="$1"
WORK_TREE=$(echo "$GIT_PATH" | sed 's/\.git$//')
gitexec() {
git --git-dir="$GIT_PATH" --work-tree="$WORK_TREE" $1
}
echo "## UPDATE $GIT_PATH"
if [[ "$1" == *git ]]; then
gitexec "status"
gitexec "reset --hard -q"
gitexec "fetch --all -q"
gitexec "merge --ff-only -q"
gitexec "remote update --prune"
# git submodule cannot work with --work-tree/--git-dir basis
# gitexec "submodule update --init --recursive --remote"
# gitexec "submodule foreach git reset --hard -q"
# gitexec "submodule foreach git gc --quiet --auto"
gitexec "gc --quiet --auto"
else
echo "## NOT GIT"
fi
#!/bin/bash
find -maxdepth 3 -name '.git' -type d -exec git_update_dir.sh \{\} \;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment