Last active
April 25, 2022 09:05
-
-
Save miguelfito/c4f653083a84ac4ea2e942878e64b9ec to your computer and use it in GitHub Desktop.
Clone all project's git repos from Bitbucket
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 | |
# Define your bitbucket server URL | |
BITBUCKET_SERVER=bitbucket.organization.com | |
# Define your credentials | |
USERNAME=your_login | |
PASSWORD=your_password | |
# Save current dir | |
root_folder=$PWD | |
for project in $(curl -s --user $USERNAME:$PASSWORD --request GET https://$BITBUCKET_SERVER/rest/api/1.0/projects?limit=1000 | jq --raw-output '.values[].key') | |
do | |
# Create project folder if it doesn't exist | |
if [ ! -d ${project} ]; then | |
echo -en " [\033[34mCreating project $project folder\033[0m]\n" | |
mkdir $project | |
echo -en " [\033[32mCreated\033[0m]\n" | |
fi | |
# Step into folder | |
cd $project | |
# Clone every repo in this project (http) | |
for repo in $(curl -s --user $USERNAME:$PASSWORD --request GET https://$BITBUCKET_SERVER/rest/api/1.0/projects/$project/repos?limit=1000 | jq --raw-output '.values[].links.clone[].href | select(. | contains("http"))') | |
do | |
echo -en " [\033[34mCloning $repo in $project\033[0m]\n" | |
git clone $repo | |
echo -en " [\033[32mCloned\033[0m]\n" | |
done | |
# Back to root folder | |
cd $root_folder | |
done | |
echo -en " [\033[32mDone\033[0m]\n" | |
# OPTIONAL: Update all refs | |
#./update_git_repos.sh |
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 | |
# update_git_repos.sh | |
# Place this script at same level of download_bitbucket_repos.sh | |
# store the current dir | |
CUR_DIR=$(pwd) | |
# Let the person running the script know what's going on. | |
echo -e "\n\033[1mFetching in latest changes for all repositories...\033[0m\n" | |
# Find all git repositories and update it to the master latest revision | |
for i in $(find . -name ".git" | cut -c 3-); do | |
echo ""; | |
echo -e "\033[33m"$(dirname $i)"\033[0m"; | |
# We have to go to the .git parent directory to call the pull command | |
cd "$i"; | |
cd ..; | |
# Checkout to develop version | |
git checkout develop; | |
git reset --hard origin/develop; | |
# Fetch all refs and delete old ones | |
git fetch --all --prune --tags; | |
# Pull new changes | |
git pull; | |
# Initialize gitflow to defaults | |
git flow init --defaults --force | |
# lets get back to the CUR_DIR | |
cd $CUR_DIR | |
done | |
echo -e "\n\033[32mComplete!\033[0m\n" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment