Shell script to automatically rebase and merge your PRs when they are out-of-date
- GitHub CLI
- Auto-merge must be allowed in the repository (See here)
- Clone this repository
git clone https://github.com/xmac11/merge-it.git- Set the
GH_TOKENenvironment variable
For example, if you are using zsh:
echo 'export GH_TOKEN=your-token' >> ~/.zprofile- Create a cron job
Run:
crontab -eand schedule the cron job. For example, if you are using zsh and you want to merge feature-branch into develop for a repository named my-repo owned by my-company:
* * * * * source ~/.zprofile; /path/to/script/merge_it.sh /path/to/repo my-company my-repo develop feature-branch >> /path/to/script/mergeit.log 2>&1- A PR must have been already opened manually.
- A single PR must exist for a given branch.
- The first time the script runs, it enables auto-merge. However, if you disable it, you will have to re-enable it manually.
- When the branch is merged, running the script will do nothing. Nonetheless, you should remove the cron job. Ideally, this would be done automatically, and might be added in the future.
-
(macOS)
Operation not permittedwhen cron runs the script
GivecronFull Disc Access (source) -
gh: command not foundwhen cron runs the script
Make sure that GitHub CLI is installed and present in thePATHwhen the cron job runs.
For example, if the GitHub CLI was installed withHomebrewand you are usingzsh:
echo 'eval "$(/opt/homebrew/bin/brew shellenv)"' >> ~/.zprofile 


