complex-feature.md

  1<!--
  2  GOLD STANDARD EXAMPLE: Complex Feature Documentation
  3
  4  This example demonstrates documentation for a major feature with multiple
  5  sub-features, configuration options, and an action reference table.
  6
  7  Key patterns to note:
  8  - Anchor IDs on all major sections for stable deep-linking
  9  - Opening paragraph explains what and why
 10  - Configuration section with JSON examples
 11  - Proper callout formatting (> **Note:** and > **Tip:**)
 12  - Comprehensive action reference table at the end
 13  - Uses {#action ...} and {#kb ...} syntax throughout
 14-->
 15
 16---
 17
 18description: Zed is a text editor that supports lots of Git features
 19title: Zed Editor Git integration documentation
 20
 21---
 22
 23# Git
 24
 25Zed has built-in Git support that lets you manage version control without leaving the editor. The Git Panel shows your working tree state, staging area, and branch information. Changes you make on the command line are reflected immediately in Zed.
 26
 27For operations that Zed doesn't support natively, you can use the integrated terminal.
 28
 29## Git Panel {#git-panel}
 30
 31The Git Panel shows the state of your working tree and Git's staging area.
 32
 33You can open the Git Panel using {#action git_panel::ToggleFocus}, or by clicking the Git icon in the status bar.
 34
 35In the panel you can see the state of your project at a glance: which repository and branch are active, what files have changed and the current staging state of each file.
 36
 37Zed monitors your repository so that changes you make on the command line are instantly reflected.
 38
 39### Configuration {#configuration}
 40
 41Open the Settings Editor (`Cmd+,` on macOS, `Ctrl+,` on Linux/Windows) to customize Git behavior. Settings are spread across two pages:
 42
 43- **Panels > Git Panel**: Panel position, tree vs flat view, status display style
 44- **Version Control**: Gutter indicators, inline blame, hunk styles
 45
 46#### Moving the Git Panel
 47
 48By default, the Git Panel docks on the left. Go to **Panels > Git Panel** and change **Git Panel Dock** to move it to the right or bottom.
 49
 50#### Switching to Tree View
 51
 52The Git Panel shows a flat list of changed files by default. To see files organized by folder hierarchy instead, toggle **Tree View** in the panel's context menu, or enable it in **Panels > Git Panel**.
 53
 54#### Inline Blame
 55
 56Zed shows Git blame information on the current line. To turn this off or add a delay before it appears, go to **Version Control > Inline Git Blame**.
 57
 58#### Hiding the Gutter Indicators
 59
 60The colored bars in the gutter that show added, modified, and deleted lines can be hidden. Go to **Version Control > Git Gutter** and set **Visibility** to "Hide".
 61
 62#### Commit Message Line Length
 63
 64Zed wraps commit messages at 72 characters (a Git convention). To change this, search for "Git Commit" in Settings and adjust **Preferred Line Length**.
 65
 66## Project Diff {#project-diff}
 67
 68You can see all of the changes captured by Git in Zed by opening the Project Diff ({#kb git::Diff}), accessible via the {#action git::Diff} action in the Command Palette or the Git Panel.
 69
 70All of the changes displayed in the Project Diff behave exactly the same as any other multibuffer: they are all editable excerpts of files.
 71
 72You can stage or unstage each hunk as well as a whole file by hitting the buttons on the tab bar or their corresponding keybindings.
 73
 74### Word Diff Highlighting {#word-diff}
 75
 76By default, Zed highlights changed words within modified lines to make it easier to spot exactly what changed. To disable this globally, open the Settings Editor and go to **Languages & Tools > Miscellaneous**, then turn off **Word Diff Enabled**.
 77
 78To disable word diff for specific languages only, add this to your settings.json:
 79
 80```json
 81{
 82  "languages": {
 83    "Markdown": {
 84      "word_diff_enabled": false
 85    }
 86  }
 87}
 88```
 89
 90## File History {#file-history}
 91
 92File History shows the commit history for an individual file. Each entry displays the commit's author, timestamp, and message. Selecting a commit opens a diff view filtered to show only the changes made to that file in that commit.
 93
 94To open File History:
 95
 96- Right-click on a file in the Project Panel and select "Open File History"
 97- Right-click on a file in the Git Panel and select "Open File History"
 98- Right-click on an editor tab and select "Open File History"
 99- Use the Command Palette and search for "file history"
100
101## Fetch, Push, and Pull {#fetch-push-pull}
102
103Fetch, push, or pull from your Git repository in Zed via the buttons available on the Git Panel or via the Command Palette by looking at the respective actions: {#action git::Fetch}, {#action git::Push}, and {#action git::Pull}.
104
105### Push Configuration {#push-configuration}
106
107Zed respects Git's push configuration. When pushing, Zed checks the following in order:
108
1091. `pushRemote` configured for the current branch
1102. `remote.pushDefault` in your Git config
1113. The branch's tracking remote
112
113This matches Git's standard behavior, so if you've configured `pushRemote` or `pushDefault` in your `.gitconfig` or via `git config`, Zed will use those settings.
114
115## Remotes {#remotes}
116
117When your repository has multiple remotes, Zed shows a remote selector in the Git Panel. Click the remote button next to push/pull to choose which remote to use for that operation.
118
119## Staging Workflow {#staging-workflow}
120
121Zed has two primary staging workflows, using either the Project Diff or the panel directly.
122
123### Using the Project Diff {#staging-project-diff}
124
125In the Project Diff view, you can focus on each hunk and stage them individually by clicking on the tab bar buttons or via the keybindings {#action git::StageAndNext} ({#kb git::StageAndNext}).
126
127Similarly, stage all hunks at the same time with the {#action git::StageAll} ({#kb git::StageAll}) keybinding and then immediately commit with {#action git::Commit} ({#kb git::Commit}).
128
129### Using the Git Panel {#staging-git-panel}
130
131From the panel, you can simply type a commit message and hit the commit button, or {#action git::Commit}. This will automatically stage all tracked files (indicated by a `[·]` in the entry's checkbox) and commit them.
132
133Entries can be staged using each individual entry's checkbox. All changes can be staged using the button at the top of the panel, or {#action git::StageAll}.
134
135## Committing {#committing}
136
137Zed offers two commit textareas:
138
1391. The first one is available right at the bottom of the Git Panel. Hitting {#kb git::Commit} immediately commits all of your staged changes.
1402. The second is available via the action {#action git::ExpandCommitEditor} or via hitting the {#kb git::ExpandCommitEditor} while focused in the Git Panel commit textarea.
141
142### Undoing a Commit {#undo-commit}
143
144As soon as you commit in Zed, in the Git Panel, you'll see a bar right under the commit textarea, which will show the recently submitted commit.
145In there, you can use the "Uncommit" button, which performs the `git reset HEADˆ--soft` command.
146
147### Configuring Commit Line Length
148
149By default, Zed sets the commit line length to `72` but it can be configured in your local `settings.json` file.
150
151Find more information about setting the `preferred-line-length` in the [Configuration](#configuration) section.
152
153## Branch Management {#branch-management}
154
155### Creating and Switching Branches {#create-switch-branches}
156
157Create a new branch using {#action git::Branch} or switch to an existing branch using {#action git::Switch} or {#action git::CheckoutBranch}.
158
159### Deleting Branches {#delete-branches}
160
161To delete a branch, open the branch switcher with {#action git::Switch}, find the branch you want to delete, and use the delete option. Zed will confirm before deleting to prevent accidental data loss.
162
163> **Note:** You cannot delete the branch you currently have checked out. Switch to a different branch first.
164
165## Merge Conflicts {#merge-conflicts}
166
167When you encounter merge conflicts after a merge, rebase, or pull, Zed highlights the conflicting regions in your files and displays resolution buttons above each conflict.
168
169### Viewing Conflicts {#viewing-conflicts}
170
171Conflicting files appear in the Git Panel with a warning icon. You can also see conflicts in the Project Diff view, where each conflict region is highlighted:
172
173- Changes from your current branch are highlighted in green
174- Changes from the incoming branch are highlighted in blue
175
176### Resolving Conflicts {#resolving-conflicts}
177
178Each conflict shows three buttons:
179
180- **Use [branch-name]**: Keep the changes from one branch (shows the actual branch name, like "main")
181- **Use [other-branch]**: Keep the changes from the other branch (like "feature-branch")
182- **Use Both**: Keep both sets of changes, with your branch's changes first
183
184Click a button to resolve that conflict. The conflict markers are removed and replaced with your chosen content. After resolving all conflicts in a file, stage it and commit to complete the merge.
185
186> **Tip:** For complex conflicts that need manual editing, you can edit the file directly. Remove the conflict markers (`<<<<<<<`, `=======`, `>>>>>>>`) and keep the content you want.
187
188## Stashing {#stashing}
189
190Git stash allows you to temporarily save your uncommitted changes and revert your working directory to a clean state. This is particularly useful when you need to quickly switch branches or pull updates without committing incomplete work.
191
192### Creating Stashes {#creating-stashes}
193
194To stash all your current changes, use the {#action git::StashAll} action. This will save both staged and unstaged changes to a new stash entry and clean your working directory.
195
196### Managing Stashes {#managing-stashes}
197
198Zed provides a stash picker accessible via {#action git::ViewStash} or from the Git Panel's overflow menu. From the stash picker, you can:
199
200- **View stash list**: Browse all your saved stashes with their descriptions and timestamps
201- **Open diffs**: See exactly what changes are stored in each stash
202- **Apply stashes**: Apply stash changes to your working directory while keeping the stash entry
203- **Pop stashes**: Apply stash changes and remove the stash entry from the list
204- **Drop stashes**: Delete unwanted stash entries without applying them
205
206### Quick Stash Operations {#quick-stash}
207
208For faster workflows, Zed provides direct actions to work with the most recent stash:
209
210- **Apply latest stash**: Use {#action git::StashApply} to apply the most recent stash without removing it
211- **Pop latest stash**: Use {#action git::StashPop} to apply and remove the most recent stash
212
213### Stash Diff View {#stash-diff-view}
214
215To view a stash's contents, select it in the stash picker and press {#kb stash_picker::ShowStashItem}. From the diff view, you can use these keybindings:
216
217| Action                               | Keybinding                   |
218| ------------------------------------ | ---------------------------- |
219| Apply stash                          | {#kb git::ApplyCurrentStash} |
220| Pop stash (apply and remove)         | {#kb git::PopCurrentStash}   |
221| Drop stash (remove without applying) | {#kb git::DropCurrentStash}  |
222
223## AI Support in Git {#ai-support}
224
225Zed currently supports LLM-powered commit message generation.
226You can ask AI to generate a commit message by focusing on the message editor within the Git Panel and either clicking on the pencil icon in the bottom left, or reaching for the {#action git::GenerateCommitMessage} ({#kb git::GenerateCommitMessage}) keybinding.
227
228> **Note:** You need to have an LLM provider configured either via your own API keys or through Zed's hosted AI models.
229> Visit [the AI configuration page](./ai/configuration.md) to learn how to do so.
230
231You can specify your preferred model to use by providing a `commit_message_model` agent setting.
232See [Feature-specific models](./ai/agent-settings.md#feature-specific-models) for more information.
233
234```json [settings]
235{
236  "agent": {
237    "commit_message_model": {
238      "provider": "anthropic",
239      "model": "claude-3-5-haiku"
240    }
241  }
242}
243```
244
245To customize the format of generated commit messages, run {#action agent::OpenRulesLibrary} and select the "Commit message" rule on the left side.
246From there, you can modify the prompt to match your desired format.
247
248Any specific instructions for commit messages added to [Rules files](./ai/rules.md) are also picked up by the model tasked with writing your commit message.
249
250## Git Integrations {#git-integrations}
251
252Zed integrates with popular Git hosting services to ensure that Git commit hashes and references to Issues, Pull Requests, and Merge Requests become clickable links.
253
254Zed currently supports links to the hosted versions of
255[GitHub](https://github.com),
256[GitLab](https://gitlab.com),
257[Bitbucket](https://bitbucket.org),
258[SourceHut](https://sr.ht) and
259[Codeberg](https://codeberg.org).
260
261### Self-Hosted Instances {#self-hosted}
262
263Zed automatically identifies Git hosting providers by checking for keywords in your Git remote URL. For example, if your self-hosted URL contains `gitlab`, `gitea`, or other recognized provider names, Zed will automatically register that hosting provider without any configuration needed.
264
265However, if your self-hosted Git instance URL doesn't contain identifying keywords, you can manually configure Zed to create clickable links to your instance by adding a `git_hosting_providers` setting so commit hashes and permalinks resolve to your domain:
266
267```json [settings]
268{
269  "git_hosting_providers": [
270    {
271      "provider": "gitlab",
272      "name": "Corp GitLab",
273      "base_url": "https://git.example.corp"
274    }
275  ]
276}
277```
278
279The `provider` field specifies which type of hosting service you're using. Supported `provider` values are `github`, `gitlab`, `bitbucket`, `gitea`, `forgejo`, and `sourcehut`. The `name` is optional and used as a display name for your instance, and `base_url` is the root URL of your self-hosted server.
280
281You can configure multiple custom providers if you work with several self-hosted instances.
282
283### Permalinks {#permalinks}
284
285Zed also has a Copy Permalink feature to create a permanent link to a code snippet on your Git hosting service.
286These links are useful for sharing a specific line or range of lines in a file at a specific commit.
287Trigger this action via the [Command Palette](./getting-started.md#command-palette) (search for `permalink`),
288by creating a [custom key bindings](key-bindings.md#custom-key-bindings) to the
289`editor::CopyPermalinkToLine` or `editor::OpenPermalinkToLine` actions
290or by simply right clicking and selecting `Copy Permalink` with line(s) selected in your editor.
291
292## Diff Hunk Keyboard Shortcuts {#diff-hunks}
293
294When viewing files with changes, Zed displays diff hunks that can be expanded or collapsed for detailed review:
295
296- **Expand all diff hunks**: {#action editor::ExpandAllDiffHunks} ({#kb editor::ExpandAllDiffHunks})
297- **Collapse all diff hunks**: Press `Escape` (bound to {#action editor::Cancel})
298- **Toggle selected diff hunks**: {#action editor::ToggleSelectedDiffHunks} ({#kb editor::ToggleSelectedDiffHunks})
299- **Navigate between hunks**: {#action editor::GoToHunk} and {#action editor::GoToPreviousHunk}
300
301> **Tip:** The `Escape` key is the quickest way to collapse all expanded diff hunks and return to an overview of your changes.
302
303## Action Reference {#action-reference}
304
305| Action                                    | Keybinding                            |
306| ----------------------------------------- | ------------------------------------- |
307| {#action git::Add}                        | {#kb git::Add}                        |
308| {#action git::StageAll}                   | {#kb git::StageAll}                   |
309| {#action git::UnstageAll}                 | {#kb git::UnstageAll}                 |
310| {#action git::ToggleStaged}               | {#kb git::ToggleStaged}               |
311| {#action git::StageAndNext}               | {#kb git::StageAndNext}               |
312| {#action git::UnstageAndNext}             | {#kb git::UnstageAndNext}             |
313| {#action git::Commit}                     | {#kb git::Commit}                     |
314| {#action git::ExpandCommitEditor}         | {#kb git::ExpandCommitEditor}         |
315| {#action git::Push}                       | {#kb git::Push}                       |
316| {#action git::ForcePush}                  | {#kb git::ForcePush}                  |
317| {#action git::Pull}                       | {#kb git::Pull}                       |
318| {#action git::PullRebase}                 | {#kb git::PullRebase}                 |
319| {#action git::Fetch}                      | {#kb git::Fetch}                      |
320| {#action git::Diff}                       | {#kb git::Diff}                       |
321| {#action git::Restore}                    | {#kb git::Restore}                    |
322| {#action git::RestoreFile}                | {#kb git::RestoreFile}                |
323| {#action git::Branch}                     | {#kb git::Branch}                     |
324| {#action git::Switch}                     | {#kb git::Switch}                     |
325| {#action git::CheckoutBranch}             | {#kb git::CheckoutBranch}             |
326| {#action git::Blame}                      | {#kb git::Blame}                      |
327| {#action git::StashAll}                   | {#kb git::StashAll}                   |
328| {#action git::StashPop}                   | {#kb git::StashPop}                   |
329| {#action git::StashApply}                 | {#kb git::StashApply}                 |
330| {#action git::ViewStash}                  | {#kb git::ViewStash}                  |
331| {#action editor::ToggleGitBlameInline}    | {#kb editor::ToggleGitBlameInline}    |
332| {#action editor::ExpandAllDiffHunks}      | {#kb editor::ExpandAllDiffHunks}      |
333| {#action editor::ToggleSelectedDiffHunks} | {#kb editor::ToggleSelectedDiffHunks} |
334
335> **Note:** Not all actions have default keybindings, but can be bound by [customizing your keymap](./key-bindings.md#user-keymaps).
336
337## Git CLI Configuration {#cli-configuration}
338
339If you would like to also use Zed for your [git commit message editor](https://git-scm.com/book/en/v2/Customizing-Git-Git-Configuration#_core_editor) when committing from the command line you can use `zed --wait`:
340
341```sh
342git config --global core.editor "zed --wait"
343```
344
345Or add the following to your shell environment (in `~/.zshrc`, `~/.bashrc`, etc):
346
347```sh
348export GIT_EDITOR="zed --wait"
349```