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

Panning for info.

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:

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! 😸😸😸


Subscribe via RSS, Twitter, Mastodon, or email:

One summary email a week, no spam, I pinky promise.

Related posts:

Tags: