Git: Detect an in-progress cherry-pick, merge, rebase, or revert

To detect if a certain operation is in progress in a Git repository, use git rev-parse like so:
$ git rev-parse --verify <name>
…where <name> is one of the special commit references that Git creates during those operations. Here’s the list of per-operation commands with substituted names:
Cherry-pick:
$ git rev-parse --verify CHERRY_PICK_HEAD
Merge:
$ git rev-parse --verify MERGE_HEAD
Rebase:
$ git rev-parse --verify REBASE_HEAD
Revert:
$ git rev-parse --verify REVERT_HEAD
If the picked operation is in progress, the command will succeed and output the operated on SHA. If not, it will fail with an error message and an exit code of 128.
For example, detecting a cherry-pick in progress:
$ git rev-parse --verify CHERRY_PICK_HEAD
470dc6a4bbdbb690db6d33b966d0ed8638144909
And detecting that no cherry-pick is in progress:
$ git rev-parse --verify CHERRY_PICK_HEAD
fatal: Needed a single revision
$ echo $?
128
Enjoy.
—Adam
😸😸😸 Check out my new book on using GitHub effectively, Boost Your GitHub DX! 😸😸😸
One summary email a week, no spam, I pinky promise.
Related posts:
Tags: git