You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Provide a way for git hooks to know whether they're being run from Github Desktop #19001
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?
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.
With this new support GitHub Desktop will set a GITHUB_DESKTOP=1 environment variable when invoking commit hooks.
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
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.
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.
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
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.
With this new support GitHub Desktop will set a GITHUB_DESKTOP=1 environment variable when invoking commit hooks.
Activity
[-]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[/+]steveward commentedon Jul 22, 2024
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.
patreeceeo commentedon Jul 22, 2024
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.
niik commentedon Sep 18, 2024
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 likeGITHUB_DESKTOP=1niik commentedon Jan 14, 2026
Yesterday we shipped GitHub Desktop 3.5.5-beta1 to our beta channel with improved support for hooks related to committing.
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.
With this new support GitHub Desktop will set a
GITHUB_DESKTOP=1environment variable when invoking commit hooks.Recognize GitHub Desktop by GITHUB_DESKTOP, as Desktop 3.5+ runs hooks
Recognize GitHub Desktop by GITHUB_DESKTOP, as Desktop 3.5+ runs hooks
Recognize GitHub Desktop by GITHUB_DESKTOP, as Desktop 3.5+ runs hooks