Created
January 14, 2026 19:22
-
-
Save aessing/8f494b882277d17dacdd0525da710b15 to your computer and use it in GitHub Desktop.
Script that updates all GIT repositories in subdirectories of the actual folder.
This file contains hidden or 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
| #!/usr/bin/env bash | |
| # ============================================================================= | |
| # Helper Script: git-sync-all.sh | |
| # Updates all git repositories in subdirectories | |
| # ----------------------------------------------------------------------------- | |
| # Developer.......: Andre Essing (https://github.com/aessing) | |
| # (https://www.linkedin.com/in/aessing/) | |
| # ----------------------------------------------------------------------------- | |
| # THE CODE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |
| # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
| # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | |
| # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |
| # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | |
| # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | |
| # SOFTWARE. | |
| # ============================================================================= | |
| # Color codes | |
| BOLD='\033[1m' | |
| GREEN='\033[0;32m' | |
| BLUE='\033[0;34m' | |
| YELLOW='\033[1;33m' | |
| RED='\033[0;31m' | |
| RESET='\033[0m' | |
| # Store the current directory | |
| ORIGINAL_DIR=$(pwd) | |
| # Check for --debug flag | |
| DEBUG=false | |
| if [[ "$1" == "--debug" ]]; then | |
| DEBUG=true | |
| fi | |
| echo "" | |
| echo -e "${BOLD}${BLUE}═══════════════════════════════════════════════════════════${RESET}" | |
| echo -e "${BOLD}${GREEN}🔄 GIT Sync - Repository Refresh Tool${RESET}" | |
| echo -e "${BOLD}${BLUE}═══════════════════════════════════════════════════════════${RESET}" | |
| echo "" | |
| echo -e "${BOLD}Starting directory:${RESET} $ORIGINAL_DIR" | |
| echo "" | |
| # Array to track skipped folders | |
| SKIPPED_DIRS=() | |
| # Function to process a directory | |
| process_dir() { | |
| local dir=$1 | |
| # Enter the directory | |
| cd "$dir" || { | |
| echo -e "${RED}✗ Error: Could not enter directory $dir${RESET}" | |
| return 1 | |
| } | |
| # Check if it's a git repository | |
| if [ -d ".git" ]; then | |
| echo -e "${BLUE}📁 $dir${RESET}" | |
| echo -e "${GREEN}✓ Running git fetch --all --prune...${RESET}" | |
| git fetch --all --prune | |
| echo "" | |
| else | |
| SKIPPED_DIRS+=("$dir") | |
| fi | |
| # Go back to the original directory | |
| cd "$ORIGINAL_DIR" || { | |
| echo -e "${RED}✗ Error: Could not return to original directory${RESET}" | |
| exit 1 | |
| } | |
| } | |
| # Loop through all top-level subdirectories | |
| for dir in */; do | |
| # Check if it's actually a directory | |
| if [ -d "$dir" ]; then | |
| process_dir "$dir" | |
| # Loop through second-level subdirectories (1 level deep) | |
| for subdir in "$dir"*/; do | |
| # Check if it's actually a directory | |
| if [ -d "$subdir" ]; then | |
| process_dir "$subdir" | |
| fi | |
| done | |
| fi | |
| done | |
| echo -e "${BOLD}${BLUE}═══════════════════════════════════════════════════════════${RESET}" | |
| echo -e "${BOLD}${GREEN}✓ Finished processing all subdirectories${RESET}" | |
| echo -e "${BOLD}${BLUE}═══════════════════════════════════════════════════════════${RESET}" | |
| echo "" | |
| # Show summary of skipped folders (only with --debug flag) | |
| if [ "$DEBUG" = true ] && [ ${#SKIPPED_DIRS[@]} -gt 0 ]; then | |
| echo -e "${BOLD}${YELLOW}Skipped folders (not git repositories):${RESET}" | |
| for dir in "${SKIPPED_DIRS[@]}"; do | |
| echo -e " ${YELLOW}⊘ $dir${RESET}" | |
| done | |
| echo "" | |
| fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment