Last active
March 14, 2025 14:31
-
-
Save torrespro/63b348859de52b5ab48f82f750082c9d to your computer and use it in GitHub Desktop.
Script to clone or update multiple repositories, the script checks if each repository exists, updates it if it does, or clones it if it doesn't
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
#!/bin/bash | |
# Script to clone or update multiple repositories | |
# This script checks if each repository exists, updates it if it does, or clones it if it doesn't | |
# Create a function to clone or update a repository | |
clone_or_update_repo() { | |
local repo_url=$1 | |
local repo_name=$(basename "$repo_url" .git | sed 's/\.git$//') | |
echo "Processing $repo_name..." | |
if [ -d "$repo_name" ]; then | |
echo " Repository exists. Updating..." | |
cd "$repo_name" | |
git pull | |
cd .. | |
else | |
echo " Repository doesn't exist. Cloning..." | |
git clone "$repo_url" | |
fi | |
echo " Done with $repo_name" | |
echo "" | |
} | |
# List of repositories to clone/update | |
repos=( | |
"[email protected]:your-repo.git" | |
"[email protected]:another-repo.git" | |
) | |
echo "Starting | |
repository management..." | |
echo "Will process ${#repos[@]} repositories" | |
echo "" | |
# Clone or update each repository | |
for repo in "${repos[@]}"; do | |
clone_or_update_repo "$repo" | |
done | |
echo "All repositories have been processed!" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment