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_TOKEN
environment variable
For example, if you are using zsh
:
echo 'export GH_TOKEN=your-token' >> ~/.zprofile
- Create a cron job
Run:
crontab -e
and 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 permitted
when cron runs the script
Givecron
Full Disc Access (source) -
gh: command not found
when cron runs the script
Make sure that GitHub CLI is installed and present in thePATH
when the cron job runs.
For example, if the GitHub CLI was installed withHomebrew
and you are usingzsh
:
echo 'eval "$(/opt/homebrew/bin/brew shellenv)"' >> ~/.zprofile