Created
January 10, 2018 09:52
-
-
Save smarek/e71cfb7028ada8ad9c3b6af9e1023a2e to your computer and use it in GitHub Desktop.
Update all git repositories in subfolders (worktree max 2-levels deep)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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