Skip to content

Instantly share code, notes, and snippets.

@Justintime50
Last active June 30, 2022 16:32
Show Gist options
  • Save Justintime50/1d27e86461e77d8a66da3ac36e1ef181 to your computer and use it in GitHub Desktop.
Save Justintime50/1d27e86461e77d8a66da3ac36e1ef181 to your computer and use it in GitHub Desktop.
Push any changes from each repo in the current directory - great for mass updating repos at once.
#!/bin/bash
# Copy a set of files to each repo in a dir, create a branch, and push to origin
# Requires GitHub CLI: `brew install gh` and must be logged in with `gh auth login`
# GitHub CLI Docs: https://cli.github.com/manual/
MAIN_BRANCH="master"
BRANCH_NAME="ignore_cassette_diffs"
COMMIT_MESSAGE="chore: ignore cassette diffs via gitattributes"
PR_TITLE="$COMMIT_MESSAGE"
PR_BODY="Ignore cassette diffs locally (line 1) and collapse on GitHub (line 2) for easier review."
copy_files() {
# Add copy commands here for each project to receive
cp ../.gitattributes .gitattributes
}
main() {
echo "Pushing changes for each repo..."
for DIR in */; do
# Switch to the repo
printf '\n%s\n' "$DIR"
cd "$DIR" || exit 1
# Setup our branch
git status
echo "We are about to stash the above changes and switch branches, press any button to proceed"
read -rn 1
git stash
git checkout "$MAIN_BRANCH"
git pull
git checkout -b "$BRANCH_NAME"
# Copy our files to each repo
echo "Copying files to repo..."
copy_files
# Add/commit changes to our branch
echo "Committing changes to repo..."
git add .
git commit -m "$COMMIT_MESSAGE"
# Push changes and create PR (push up local branch, create PR via GitHub CLI)
echo "Creating PR for repo..."
git push --set-upstream origin "$BRANCH_NAME"
gh pr create -t "$PR_TITLE" -b "$PR_BODY" --base "$MAIN_BRANCH"
# Move on to the next repo
cd .. || exit 1
done
echo "Script complete!"
}
main
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment