Skip to content

Instantly share code, notes, and snippets.

@eps1lon
Last active December 6, 2023 09:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eps1lon/960f3b575dc2ffeff5c04206069906af to your computer and use it in GitHub Desktop.
Save eps1lon/960f3b575dc2ffeff5c04206069906af to your computer and use it in GitHub Desktop.
Split branch into one branch per folder
#!/bin/bash
set -e
branchToSplit="feat/react/deprecated-react-node-array"
title="Remove usage of deprecated ReactChild"
message="This PR removes the usage of the deprecated \`ReactChild\` type (see https://github.com/DefinitelyTyped/DefinitelyTyped/discussions/64451)."
mergeBase=$(git merge-base origin/master $branchToSplit)
types=( $(git diff --name-only $mergeBase $branchToSplit | grep -oE 'types/[^/]+/' | cut -d/ -f2 | uniq) )
for type in "${types[@]}"; do
echo "Splitting $type"
branchName="$branchToSplit-split/$type"
git checkout -b "$branchName" master
git checkout "$branchToSplit" -- "types/$type"
prTitle="[$type] $title"
git commit -a -m "$prTitle"
git push -u origin HEAD
gh pr create \
--title "$prTitle" \
--body "$message";
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment