Skip to content

Instantly share code, notes, and snippets.

@Sekiphp
Created November 19, 2023 21:16
Show Gist options
  • Save Sekiphp/abd7cfe74d6bce92893ed8efafc57714 to your computer and use it in GitHub Desktop.
Save Sekiphp/abd7cfe74d6bce92893ed8efafc57714 to your computer and use it in GitHub Desktop.
Init git repositories in vendor in case when all repos in folder are from same git and follows directory naming pattern. Useful for Magento 2 projects.
#!/bin/bash
COLOR_RED="\033[0;31m"
clear
# iterate folders
ls -d */ | tr -d "/" | while read -r folder;
do
GIT_TOPLEVEL_FOLDER=$(git -C $folder rev-parse --show-toplevel)
CURRENT_FOLDER=$(pwd)'/'$folder
if [[ "${GIT_TOPLEVEL_FOLDER}" != "${CURRENT_FOLDER}" ]];
then
echo -e "$COLOR_RED"
echo "Folder ${folder} is not git repository!"
cd "$folder"
git clone [email protected]:v3/org/project2022/magento2-"$folder"
mv "magento2-"$folder"/.git" .git
rm -rf "magento2-"$folder""
cd ..
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment