Q: git: how can I easily tell if I'm in the middle of a rebase I'm writing a bash one-liner where I want to do something automatically every time I run git rebase --continue inside a while [ true ] loop. When it stops, if I'm still rebasing, I will do X, then I will ask rebase to continue again. Is there an easy easy to tell if I'm still rebasing? I tried with if [ ! -f .git/REBASE_HEAD ]; then break; fi but the file is still present after rebase is finished. I see that .git/rebase-merge is present while rebasing and gone after it's done. Can I use it as my tip?

A: We can see how git-prompt.sh detects being in a rebase.
    if [ -d "$g/rebase-merge" ]; then
        if [ -f "$g/rebase-merge/interactive" ]; then
            r="|REBASE-i"
        else
            r="|REBASE-m"
        fi
    else
        if [ -d "$g/rebase-apply" ]; then
            if [ -f "$g/rebase-apply/rebasing" ]; then
                r="|REBASE"
            elif [ -f "$g/rebase-apply/applying" ]; then
                r="|AM"
            else
                r="|AM/REBASE"
            fi
        elif [ -f "$g/MERGE_HEAD" ]; then
            r="|MERGING"
        elif __git_sequencer_status; then
            :
        elif [ -f "$g/BISECT_LOG" ]; then
            r="|BISECTING"
        fi

And there are additional statuses in __git_sequencer_status.
Because the Git directory is not always .git, the script uses git rev-parse --git-dir to get the git directory ($g above). Then you can see from the above which directories and files inside correspond to what actions.
Boiling that down, you're looking for one of two directories.


*

*$g/rebase-merge

*$g/rebase-apply

A: Yes, that works. Look how git-prompt.sh does it to set your PS1:
if [ -d "$g/rebase-merge" ]; then
    __git_eread "$g/rebase-merge/head-name" b
    __git_eread "$g/rebase-merge/msgnum" step
    __git_eread "$g/rebase-merge/end" total
    if [ -f "$g/rebase-merge/interactive" ]; then
        r="|REBASE-i"
    else
        r="|REBASE-m"
    fi
else
    if [ -d "$g/rebase-apply" ]; then
        __git_eread "$g/rebase-apply/next" step
        __git_eread "$g/rebase-apply/last" total
        if [ -f "$g/rebase-apply/rebasing" ]; then
            __git_eread "$g/rebase-apply/head-name" b
            r="|REBASE"
        elif [ -f "$g/rebase-apply/applying" ]; then
            r="|AM"
        else
            r="|AM/REBASE"
        fi

