Last active
September 20, 2023 23:47
-
-
Save samuraitruong/7bbeea126415f369c80a528efe0d5153 to your computer and use it in GitHub Desktop.
gcloud-clone-all
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 | |
# Get the currently configured project from gcloud | |
CURRENT_PROJECT=$(gcloud config get-value project) | |
# Check if a project ID argument is provided, otherwise use the current project | |
PROJECT_ID="${1:-$CURRENT_PROJECT}" | |
# Ensure that a project ID is set | |
if [ -z "$PROJECT_ID" ]; then | |
echo "Error: No project ID provided and no default project set." | |
exit 1 | |
fi | |
# Create a sub-folder named after the project ID | |
SUB_FOLDER="$PROJECT_ID" | |
# Loop through and clone repositories in the specified project | |
for repo in $(gcloud source repos list --project="$PROJECT_ID" --format="value(name)"); do | |
# Check if the local repository folder already exists | |
if [ ! -d "$SUB_FOLDER/$repo" ]; then | |
# Use gcloud source repos clone with the destination folder | |
gcloud source repos clone "$repo" "$SUB_FOLDER/$repo" | |
else | |
echo "Skipping repository '$repo' as the local folder '$SUB_FOLDER/$repo' already exists." | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment