Skip to content

Commit d72e362

Browse files
CopilotmxieCopilotsaritai
authored
Add GitHub Desktop v3.5.5 Git hooks documentation (#60094)
Co-authored-by: Melissa Xie <mxie@users.noreply.github.com> Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Co-authored-by: Sarita Iyer <66540150+saritai@users.noreply.github.com>
1 parent 9905804 commit d72e362

7 files changed

Lines changed: 96 additions & 6 deletions

File tree

70.7 KB
Loading
229 KB
Loading

content/desktop/configuring-and-customizing-github-desktop/configuring-git-for-github-desktop.md

Lines changed: 44 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ Configuring your global author information in {% data variables.product.prodname
4343
{% data reusables.desktop.windows-choose-options %}
4444
1. In the "Options" window, click **Git**.
4545

46-
![Screenshot of the "Git" pane in the "Options" window. In the left sidebar, an option labeled "Git" is highlighted in blue and outlined in orange.](/assets/images/help/desktop/windows-select-git-pane.png)
46+
![Screenshot of the "Git" pane in the "Options" window. In the left sidebar, an option labeled "Git" is highlighted in blue.](/assets/images/help/desktop/windows-select-git-pane.png)
4747

4848
{% data reusables.desktop.name-field-git-config %}
4949
{% data reusables.desktop.select-email-git-config %}
@@ -89,23 +89,62 @@ You can configure the default branch that will be used when you create a new rep
8989

9090
{% data reusables.desktop.mac-select-desktop-menu %}
9191
{% data reusables.desktop.settings-git-pane %}
92-
1. Optional, under "Default branch name for new repositories" edit the name of the default branch as needed.
92+
1. Click the **Default branch** tab.
93+
1. Edit the name of the default branch as needed.
9394
{% data reusables.desktop.click-save-git-config %}
9495

9596
{% endmac %}
9697

9798
{% windows %}
9899

99100
{% data reusables.desktop.windows-choose-options %}
100-
1. In the Options window, click **Git**.
101+
1. In the "Options" window, click **Git**.
101102

102-
![Screenshot of the "Git" pane in the "Options" window. In the left sidebar, an option labeled "Git" is highlighted in blue and outlined in orange.](/assets/images/help/desktop/windows-select-git-pane.png)
103+
![Screenshot of the "Git" pane in the "Options" window. In the left sidebar, an option labeled "Git" is highlighted in blue.](/assets/images/help/desktop/windows-select-git-pane.png)
103104

104-
1. Under "Default branch name for new repositories", select the default branch name you would like to use, or, to enter a custom name, select "Other...".
105+
1. Click the **Default branch** tab.
106+
1. Edit the name of the default branch as needed.
105107
{% data reusables.desktop.click-save-git-config %}
106108

107109
{% endwindows %}
108110

111+
## Configuring your shell environment for Git hooks
112+
113+
{% data variables.product.prodname_desktop %} runs Git hooks in your configured shell environment. This means hooks have access to the same environment variables, shell configuration files (such as `.bash_profile` or `.zshrc`), and tools as when you run Git from the command line. Tools installed via version managers, such as `nvm` or `rbenv`, will also be available to your hooks.
114+
115+
You can configure hook environment settings in the **Hooks** tab of the **Git** settings pane.
116+
117+
{% mac %}
118+
119+
{% data reusables.desktop.mac-select-desktop-menu %}
120+
{% data reusables.desktop.settings-git-pane %}
121+
1. Click the **Hooks** tab.
122+
123+
{% endmac %}
124+
125+
{% windows %}
126+
127+
{% data reusables.desktop.windows-choose-options %}
128+
1. In the "Options" window, click **Git**.
129+
130+
![Screenshot of the "Git" pane in the "Options" window. In the left sidebar, an option labeled "Git" is highlighted in blue.](/assets/images/help/desktop/windows-select-git-pane.png)
131+
132+
1. Click the **Hooks** tab.
133+
134+
{% endwindows %}
135+
136+
The following settings are available:
137+
138+
* **Load Git hook environment variables from shell**: When enabled, {% data variables.product.prodname_desktop %} loads environment variables from your shell when executing Git hooks. Enable this if your hooks depend on tools installed via version managers such as `nvm`, `rbenv`, or `asdf`.
139+
140+
{% mac %}
141+
142+
* **Cache Git hook environment variables**: Caches hook environment variables to improve performance. Disable this if your hooks rely on frequently changing environment variables.
143+
144+
{% endmac %}
145+
146+
For more information about Git hooks in {% data variables.product.prodname_desktop %}, see [AUTOTITLE](/desktop/making-changes-in-a-branch/working-with-git-hooks-in-github-desktop).
147+
109148
## Further reading
110149

111150
* [AUTOTITLE](/account-and-profile/setting-up-and-managing-your-personal-account-on-github/managing-email-preferences/adding-an-email-address-to-your-github-account)

content/desktop/making-changes-in-a-branch/committing-and-reviewing-changes-to-your-project-in-github-desktop.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,10 @@ Once you're satisfied with the changes you've chosen to include in your commit,
115115

116116
![Screenshot of the "Changes" tab. In the corner of the "Description" field, the icon for adding a co-author is outlined in orange.](/assets/images/help/desktop/add-co-author-commit.png)
117117
{% data reusables.desktop.commit-button %}
118+
119+
> [!TIP]
120+
> If your repository has pre-commit or commit-msg hooks, they will run automatically when you commit. You can bypass hooks for a specific commit by clicking {% octicon "gear" aria-label="Commit options" %} next to the commit message field and selecting **Bypass Commit Hooks**. For more information, see [AUTOTITLE](/desktop/making-changes-in-a-branch/working-with-git-hooks-in-github-desktop).
121+
118122
1. If the branch you're trying to commit to is protected, Desktop will warn you.
119123
* To move your changes, click **switch branches**.
120124
* To commit your changes to the protected branch, click **Commit to BRANCH**.
@@ -135,3 +139,4 @@ If you need to undo a commit or revise your commit history (to make it easier fo
135139
## Further reading
136140

137141
* [AUTOTITLE](/get-started/using-git)
142+
* [AUTOTITLE](/desktop/making-changes-in-a-branch/working-with-git-hooks-in-github-desktop)

content/desktop/making-changes-in-a-branch/index.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ versions:
99
children:
1010
- /managing-branches-in-github-desktop
1111
- /committing-and-reviewing-changes-to-your-project-in-github-desktop
12+
- /working-with-git-hooks-in-github-desktop
1213
- /stashing-changes-in-github-desktop
1314
- /viewing-the-branch-history-in-github-desktop
1415
- /pushing-changes-to-github-from-github-desktop
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
---
2+
title: Working with Git hooks in GitHub Desktop
3+
shortTitle: Working with Git hooks
4+
intro: 'You can run Git hooks in your shell environment and bypass commit hooks directly from {% data variables.product.prodname_desktop %}.'
5+
versions:
6+
fpt: '*'
7+
ghec: '*'
8+
ghes: '*'
9+
---
10+
11+
## About Git hooks in {% data variables.product.prodname_desktop %}
12+
13+
Git hooks are scripts that run automatically at specific points in the Git workflow, such as before or after a commit, push, or merge. They can be used to enforce code quality standards, run tests, or perform other automated tasks.
14+
15+
{% data variables.product.prodname_desktop %} runs Git hooks in your configured shell environment. Hooks have access to the same environment variables and tools as when you run Git from the command line. This means hooks that rely on tools installed via version managers (such as `nvm` or `rbenv`) or that depend on shell configuration files (such as `.bash_profile` or `.zshrc`) will work correctly.
16+
17+
Hook output is displayed in real time in the {% data variables.product.prodname_desktop %} UI, with terminal colors and formatting preserved, so you can easily read and debug the output from your hooks.
18+
19+
## Bypassing a commit hook
20+
21+
If you want to make a commit without running your pre-commit or commit-msg hooks, you can bypass them directly from {% data variables.product.prodname_desktop %}. This is equivalent to using `git commit --no-verify` on the command line.
22+
23+
You can bypass hooks preemptively before making a commit, or after a hook fails.
24+
25+
### Bypassing hooks before committing
26+
27+
1. In the "Changes" tab, write your commit message.
28+
1. Next to the commit message field, click {% octicon "gear" aria-label="Commit options" %}.
29+
1. Select **Bypass Commit Hooks**.
30+
1. Click **Commit to BRANCH**.
31+
32+
### Bypassing a failed hook
33+
34+
If a commit hook fails, {% data variables.product.prodname_desktop %} will display the hook's output and give you the option to bypass the failed hook and proceed with the commit.
35+
36+
1. Review the hook output displayed by {% data variables.product.prodname_desktop %}.
37+
1. To proceed with the commit despite the failure, click **Commit anyway**.
38+
39+
> [!WARNING]
40+
> Bypassing commit hooks overrides quality and safety checks that your team may rely on. Only bypass a hook if you understand the implications.
41+
42+
## Further reading
43+
44+
* [AUTOTITLE](/desktop/making-changes-in-a-branch/committing-and-reviewing-changes-to-your-project-in-github-desktop)
45+
* [Git hooks documentation](https://git-scm.com/docs/githooks) in the official Git reference
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
1. In the "Settings" window, click **Git**.
22

3-
![Screenshot of the "Git" pane in the "Preferences" window. In the left sidebar, an option labeled "Git" is highlighted in blue and outlined in orange.](/assets/images/help/desktop/mac-select-git-pane.png)
3+
![Screenshot of the "Git" pane in the "Settings" window. In the left sidebar, an option labeled "Git" is highlighted in blue and outlined in orange.](/assets/images/help/desktop/mac-select-git-pane.png)

0 commit comments

Comments
 (0)