Created
February 13, 2025 15:32
-
-
Save andybroomfield/cf93069fbbb49ea1491835f823ef84ce to your computer and use it in GitHub Desktop.
Split and update repo
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 | |
| # Ensure correct number of arguments | |
| if [ "$#" -ne 3 ]; then | |
| echo "Usage: $0 <USERNAME> <SOURCEREPO> <MODULENAME>" | |
| exit 1 | |
| fi | |
| # Assign arguments | |
| USERNAME=$1 | |
| SOURCEREPO=$2 | |
| MODULENAME=$3 | |
| # Get current date in YYYY-MM-DD format | |
| CURRENT_DATE=$(date +%Y-%m-%d) | |
| # Define the new branch name | |
| BRANCH_NAME="update/${CURRENT_DATE}--refresh-from-latest" | |
| # Clone the source repository | |
| git clone git@github.com:${USERNAME}/${SOURCEREPO}.git | |
| cd ${SOURCEREPO} || exit 1 | |
| # Filter the branch to extract the module | |
| git filter-branch --prune-empty --subdirectory-filter docroot/modules/custom/${MODULENAME} main | |
| # Remove old origin and add a new one | |
| git remote remove origin | |
| git remote add origin git@github.com:${USERNAME}/${MODULENAME}.git | |
| # Create and switch to the new update branch | |
| git checkout -b ${BRANCH_NAME} | |
| # Delete main branch and refresh it | |
| git branch -D main | |
| git fetch | |
| git checkout main | |
| git checkout ${BRANCH_NAME} | |
| git rebase main | |
| git push |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment