Skip to content

Provide a way for git hooks to know whether they're being run from Github Desktop #19001

Closed

Description

@patreeceeo

The feature request

I would like to have a way for my git hook scripts to know if they're being run from Github Desktop, as opposed to another interface e.g. running git from the command line.

My motivation is that I have found certain activities in my pre-commit hook cause Github Desktop to become unresponsive. I'll open a separate issue about this once I understand better what's going on, but for now I would like to be able to exit the commit if these activities need to be run and the hook is being run via Github Desktop.

Proposed solution

Set an shell environmental variable, such as:

export GIT_INTERFACE="GithubDesktop"

I don't know enough about the internals of Github Desktop to give much more detail here, but from briefly looking at the source code, this might actually require feature request for dugite?

Anyway, wherever/however the git binary is being executed, would it be possible to just set an environment variable beforehand?

Additional context

No response

Pinned by niik

Activity

  1. changed the title [-]Set an environment variable so that git hooks can know whether they're being run from Github Desktop[/-] [+]Provide a way for git hooks to know whether they're being run from Github Desktop[/+] on Jul 20, 2024
  2. steveward commented on Jul 22, 2024

    @steveward
    Contributor

    Thanks for the issue @patreeceeo! I'm going to group this feedback into #15286 where we are tracking this request. There are a few existing hooks-related issues due to GitHub Desktop not always having the same environment as your shell. #9351 is another related issue for exiting a hook and providing better output.

  3. patreeceeo commented on Jul 22, 2024

    @patreeceeo
    Author

    Thanks for the reply @steveward. Can you help me understand how this specific request is subsumed or made redundant by #9351? They seem merely incidentally related to me.

  4. niik commented on Sep 18, 2024

    @niik
    Member

    Thanks for the reply @steveward. Can you help me understand how this specific request is subsumed or made redundant by #9351? They seem merely incidentally related to me.

    I concur, while related they are different. I'm going to reopen this.

    I think we should stay away from using the GIT_ prefix just in case Git decides to add a conflicting environment variable down the line but rather something like GITHUB_DESKTOP=1

  5. reopened this on Sep 18, 2024
  6. niik commented on Jan 14, 2026

    @niik
    Member

    Yesterday we shipped GitHub Desktop 3.5.5-beta1 to our beta channel with improved support for hooks related to committing.

    Screenshot showing the GitHub Desktop commit form as a pre-commit hook is running

    The support is experimental and currently limited to our beta channel. While we believe that this release resolved this issue we're looking for real-world feedback so if you have the ability we'd appreciate it if you could download our beta channel and give it a spin. Ensure the experimental hooks support it's enabled by going to Settings -> Git -> Hooks and making sure the "Load Git hook environment variables from shell" is ticked.

    Screenshot showing the hook settings dialog

    With this new support GitHub Desktop will set a GITHUB_DESKTOP=1 environment variable when invoking commit hooks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions