Skip to content

Instantly share code, notes, and snippets.

@sblack4
Created June 28, 2022 13:27
Show Gist options
  • Save sblack4/d48c525b2b3fff370781e66ec4b8d857 to your computer and use it in GitHub Desktop.
Save sblack4/d48c525b2b3fff370781e66ec4b8d857 to your computer and use it in GitHub Desktop.
Copy all the changes from a PR into another branch or repo
#!/bin/bash
# clone to copies of the same repo, side by side
# add this script to the repo you want to copy from
# the name of the repo you want to copy to
REPO_NAME="myrepo"
# the PR number with the modifications
PR_NUMBER="5"
gh pr view $PR_NUMBER --json files --jq '.files.[].path' > files-changed.txt
while read l; do
new_file="../$REPO_NAME/$l"
file_path=$(echo $new_file | sed 's%/[^/]*$%%')
[ -d $file_path ] || mkdir -p $file_path
cp $l $new_file || rm $new_file
done <files-changed.txt
rm files-changed.txt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment