Skip to content

Instantly share code, notes, and snippets.

@apgapg
Created December 19, 2023 16:22
Show Gist options
  • Save apgapg/3b818868a63ce106b22c651e060594e5 to your computer and use it in GitHub Desktop.
Save apgapg/3b818868a63ce106b22c651e060594e5 to your computer and use it in GitHub Desktop.
Replace url with PAT in github root and nested submodules
#!/bin/bash
# Root project having .gitmodules
PROJECT[0]="."
# Another project inside root project having .gitmodules
PROJECT[1]="project1"
for i in "${PROJECT[@]}"
do
cd $i
FILE_PATH=".gitmodules"
git config --file $FILE_PATH --get-regexp url | while read url; do
git config --file=$FILE_PATH $(echo "$url" | sed -E "s|github.com/|${{ secrets.CUSTOM_GITHUB_API_TOKEN }}@github.com/|")
done
git submodule sync && git submodule update --init
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment