Skip to content

Instantly share code, notes, and snippets.

@devtooligan
Last active April 10, 2025 05:28
Show Gist options
  • Save devtooligan/59cb5e9ecff227556c5215ebd1fe7bae to your computer and use it in GitHub Desktop.
Save devtooligan/59cb5e9ecff227556c5215ebd1fe7bae to your computer and use it in GitHub Desktop.
A bash script to create pull requests for setting up a repo the old Spearbit way

makeprs.sh

A bash script to create pull requests for setting up a repo the old Spearbit way

Requirements

  1. be sure you have gh installed if you want the script to create PR's (optional)

Mac

brew install gh

Usage

  1. Create new empty repo on github
  2. mkdir and cd into the new folder
mkdir <insert repo name>
cd <insert repo name>
  1. Git init, set origin, push first commit to main
touch README.md
git init
git add README.md
git commit -m "initial commit"
git branch -M main
git remote add origin [email protected]:<insert org name>/<insert repo name>.git
git push -u origin main
  1. create new folders and copy files example:
folder1
├── folder1file1.txt
├── folder1file2.txt
└── folder1file3.txt

folder2
├── folder2file1.txt
└── folder2file2.txt

folder3
└── folder3file1.txt

  1. Save the makeprs.sh script somewhere. It can go in the current dir
  2. run the script - that's it
bash makeprs.sh

The script will iterate through each folder and create a new branch and PR with the name of the branch. The PR will include all files in the folder.

image image
#!/bin/bash
# Detect default branch: try main, then master, or fail
if git show-ref --verify --quiet refs/heads/main; then
default_branch="main"
elif git show-ref --verify --quiet refs/heads/master; then
default_branch="master"
else
echo "Error: Neither 'main' nor 'master' branch exists."
exit 1
fi
# Iterate through each directory in reverse order
ls -d */ | sort -r | while read dir; do
# Check if it's a directory
if [ -d "$dir" ]; then
# Get the directory name (folder name)
foldername=$(basename "$dir")
# Execute Git commands
git checkout -b "$foldername"
git add "$dir"/* # Add all files in the folder
git commit -m "$foldername"
git push -u origin "$foldername"
# Check if the gh CLI is installed
if ! command -v gh &>/dev/null; then
echo "GitHub CLI (gh) is not installed. Pull request not created."
else
# Create a pull request
pr_url=$(gh pr create --title "$foldername" --body "Automated PR for $foldername" --base "$default_branch")
echo "Created PR: $pr_url"
fi
git checkout "$default_branch"
# Add a newline for readability between folder operations
echo ""
fi
done
@devtooligan
Copy link
Author

  • Each of the top level folders below is represented by a pull request in this repo.
  • Comments and questions will be added as comments on the pr tagging the exact lines of code.
  • Findings will be posted as Github issues for further discussion before adding to the report.
  • This allows for communication about code without the need for pasting links or code snippets.
  • Highly recommended to "Watch" this repo for All Activity in order to be alerted when a new comment is left.
image
 <tree . -L 4 | pbcopy>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment