git.md

  1---
  2description: Zed is a text editor that supports lots of Git features
  3title: Zed Editor Git integration documentation
  4---
  5
  6# Git
  7
  8Zed 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.
  9
 10For operations that Zed doesn't support natively, you can use the integrated terminal.
 11
 12## Git Panel
 13
 14The Git Panel shows the state of your working tree and Git's staging area.
 15
 16You can open the Git Panel using {#action git_panel::ToggleFocus}, or by clicking the Git icon in the status bar.
 17
 18In 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.
 19
 20Zed monitors your repository so that changes you make on the command line are instantly reflected.
 21
 22### Configuration
 23
 24Open the Settings Editor (`Cmd+,` on macOS, `Ctrl+,` on Linux/Windows) to customize Git behavior. Settings are spread across two pages:
 25
 26- **Panels > Git Panel**: Panel position, tree vs flat view, status display style
 27- **Version Control**: Gutter indicators, inline blame, hunk styles
 28
 29#### Moving the Git Panel
 30
 31By 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.
 32
 33#### Switching to Tree View
 34
 35The 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**.
 36
 37#### Inline Blame
 38
 39Zed 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**.
 40
 41#### Hiding the Gutter Indicators
 42
 43The 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".
 44
 45#### Commit Message Line Length
 46
 47Zed wraps commit messages at 72 characters (a Git convention). To change this, search for "Git Commit" in Settings and adjust **Preferred Line Length**.
 48
 49## Project Diff
 50
 51You 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.
 52
 53All of the changes displayed in the Project Diff behave exactly the same as any other multibuffer: they are all editable excerpts of files.
 54
 55You can stage or unstage each hunk as well as a whole file by hitting the buttons on the tab bar or their corresponding keybindings.
 56
 57### Word Diff Highlighting
 58
 59By 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**.
 60
 61To disable word diff for specific languages only, add this to your settings.json:
 62
 63```json
 64{
 65  "languages": {
 66    "Markdown": {
 67      "word_diff_enabled": false
 68    }
 69  }
 70}
 71```
 72
 73### Diff View Styles
 74
 75Zed displays diffs in two modes: **split** (side-by-side comparison) or **unified** (inline changes). Split view is the default.
 76
 77#### Changing the diff view
 78
 79Open the Settings Editor ({#kb zed::OpenSettings}) and search for "diff view style". Select either **Split** or **Unified**.
 80
 81To change the default, add this to your `settings.json`:
 82
 83```json
 84{
 85  "diff_view_style": "unified"
 86}
 87```
 88
 89See [Configuring Zed](./configuring-zed.md) for more about the Settings Editor.
 90
 91#### Split vs unified
 92
 93- **Split**: Shows the original and modified versions side by side. Useful for comparing file structure or reviewing large changes.
 94- **Unified**: Shows changes inline with additions and deletions in a single view. Useful for focusing on specific line changes.
 95
 96You can switch between modes at any time. Your preference applies to [Project Diff](#project-diff), [File History](#file-history), and [Stash Diff View](#stash-diff-view). These diff views function as [multibuffers](./multibuffers.md), allowing you to edit multiple excerpts simultaneously.
 97
 98## File History
 99
100File 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.
101
102To open File History:
103
104- Right-click on a file in the Project Panel and select "Open File History"
105- Right-click on a file in the Git Panel and select "Open File History"
106- Right-click on an editor tab and select "Open File History"
107- Use the Command Palette and search for "file history"
108
109## Fetch, Push, and Pull
110
111Fetch, 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}.
112
113### Push Configuration
114
115Zed respects Git's push configuration. When pushing, Zed checks the following in order:
116
1171. `pushRemote` configured for the current branch
1182. `remote.pushDefault` in your Git config
1193. The branch's tracking remote
120
121This 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.
122
123## Remotes
124
125When 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.
126
127## Staging Workflow
128
129Zed has two primary staging workflows, using either the Project Diff or the panel directly.
130
131### Using the Project Diff
132
133In 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}).
134
135Similarly, 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}).
136
137### Using the Git Panel
138
139From 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.
140
141<!-- Show a set of changes with default staged -->
142
143Entries 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}.
144
145<!-- Add media -->
146
147## Committing
148
149Zed offers two commit textareas:
150
1511. The first one is available right at the bottom of the Git Panel. Hitting {#kb git::Commit} immediately commits all of your staged changes.
1522. 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.
153
154### Undoing a Commit
155
156As 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.
157In there, you can use the "Uncommit" button, which performs the `git reset HEADˆ--soft` command.
158
159### Configuring Commit Line Length
160
161By default, Zed sets the commit line length to `72` but it can be configured in your local `settings.json` file.
162
163Find more information about setting the `preferred-line-length` in the [Configuration](#configuration) section.
164
165## Branch Management
166
167### Creating and Switching Branches
168
169Create a new branch using {#action git::Branch} or switch to an existing branch using {#action git::Switch} or {#action git::CheckoutBranch}.
170
171### Deleting Branches
172
173To 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.
174
175> **Note:** You cannot delete the branch you currently have checked out. Switch to a different branch first.
176
177## Merge Conflicts
178
179When 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.
180
181### Viewing Conflicts
182
183Conflicting 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:
184
185- Changes from your current branch are highlighted in green
186- Changes from the incoming branch are highlighted in blue
187
188### Resolving Conflicts
189
190Each conflict shows three buttons:
191
192- **Use [branch-name]**: Keep the changes from one branch (shows the actual branch name, like "main")
193- **Use [other-branch]**: Keep the changes from the other branch (like "feature-branch")
194- **Use Both**: Keep both sets of changes, with your branch's changes first
195
196Click 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.
197
198> **Tip:** For complex conflicts that need manual editing, you can edit the file directly. Remove the conflict markers (`<<<<<<<`, `=======`, `>>>>>>>`) and keep the content you want.
199
200## Stashing
201
202Git 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.
203
204### Creating Stashes
205
206To 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.
207
208### Managing Stashes
209
210Zed provides a stash picker accessible via {#action git::ViewStash} or from the Git Panel's overflow menu. From the stash picker, you can:
211
212- **View stash list**: Browse all your saved stashes with their descriptions and timestamps
213- **Open diffs**: See exactly what changes are stored in each stash
214- **Apply stashes**: Apply stash changes to your working directory while keeping the stash entry
215- **Pop stashes**: Apply stash changes and remove the stash entry from the list
216- **Drop stashes**: Delete unwanted stash entries without applying them
217
218### Quick Stash Operations
219
220For faster workflows, Zed provides direct actions to work with the most recent stash:
221
222- **Apply latest stash**: Use {#action git::StashApply} to apply the most recent stash without removing it
223- **Pop latest stash**: Use {#action git::StashPop} to apply and remove the most recent stash
224
225### Stash Diff View
226
227To 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:
228
229| Action                               | Keybinding                   |
230| ------------------------------------ | ---------------------------- |
231| Apply stash                          | {#kb git::ApplyCurrentStash} |
232| Pop stash (apply and remove)         | {#kb git::PopCurrentStash}   |
233| Drop stash (remove without applying) | {#kb git::DropCurrentStash}  |
234
235## AI Support in Git
236
237Zed currently supports LLM-powered commit message generation.
238You 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.
239
240> Note that you need to have an LLM provider configured either via your own API keys or through Zed's hosted AI models.
241> Visit [the AI configuration page](./ai/configuration.md) to learn how to do so.
242
243You can specify your preferred model to use by providing a `commit_message_model` agent setting.
244See [Feature-specific models](./ai/agent-settings.md#feature-specific-models) for more information.
245
246```json [settings]
247{
248  "agent": {
249    "commit_message_model": {
250      "provider": "anthropic",
251      "model": "claude-3-5-haiku"
252    }
253  }
254}
255```
256
257To customize the format of generated commit messages, run {#action agent::OpenRulesLibrary} and select the "Commit message" rule on the left side.
258From there, you can modify the prompt to match your desired format.
259
260<!-- Add media -->
261
262Any 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.
263
264## Git Integrations
265
266Zed integrates with popular Git hosting services to ensure that Git commit hashes and references to Issues, Pull Requests, and Merge Requests become clickable links.
267
268Zed currently supports links to the hosted versions of
269[GitHub](https://github.com),
270[GitLab](https://gitlab.com),
271[Bitbucket](https://bitbucket.org),
272[SourceHut](https://sr.ht) and
273[Codeberg](https://codeberg.org).
274
275### Self-Hosted Instances
276
277Zed 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.
278
279However, 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:
280
281```json [settings]
282{
283  "git_hosting_providers": [
284    {
285      "provider": "gitlab",
286      "name": "Corp GitLab",
287      "base_url": "https://git.example.corp"
288    }
289  ]
290}
291```
292
293The `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.
294
295You can configure multiple custom providers if you work with several self-hosted instances.
296
297### Permalinks
298
299Zed also has a Copy Permalink feature to create a permanent link to a code snippet on your Git hosting service.
300These links are useful for sharing a specific line or range of lines in a file at a specific commit.
301Trigger this action via the [Command Palette](./getting-started.md#command-palette) (search for `permalink`),
302by creating a [custom key bindings](key-bindings.md#custom-key-bindings) to the
303`editor::CopyPermalinkToLine` or `editor::OpenPermalinkToLine` actions
304or by simply right clicking and selecting `Copy Permalink` with line(s) selected in your editor.
305
306## Diff Hunk Keyboard Shortcuts
307
308When viewing files with changes, Zed displays diff hunks that can be expanded or collapsed for detailed review:
309
310- **Expand all diff hunks**: {#action editor::ExpandAllDiffHunks} ({#kb editor::ExpandAllDiffHunks})
311- **Collapse all diff hunks**: Press `Escape` (bound to {#action editor::Cancel})
312- **Toggle selected diff hunks**: {#action editor::ToggleSelectedDiffHunks} ({#kb editor::ToggleSelectedDiffHunks})
313- **Navigate between hunks**: {#action editor::GoToHunk} and {#action editor::GoToPreviousHunk}
314
315> **Tip:** The `Escape` key is the quickest way to collapse all expanded diff hunks and return to an overview of your changes.
316
317## Action Reference
318
319| Action                                    | Keybinding                            |
320| ----------------------------------------- | ------------------------------------- |
321| {#action git::Add}                        | {#kb git::Add}                        |
322| {#action git::StageAll}                   | {#kb git::StageAll}                   |
323| {#action git::UnstageAll}                 | {#kb git::UnstageAll}                 |
324| {#action git::ToggleStaged}               | {#kb git::ToggleStaged}               |
325| {#action git::StageAndNext}               | {#kb git::StageAndNext}               |
326| {#action git::UnstageAndNext}             | {#kb git::UnstageAndNext}             |
327| {#action git::Commit}                     | {#kb git::Commit}                     |
328| {#action git::ExpandCommitEditor}         | {#kb git::ExpandCommitEditor}         |
329| {#action git::Push}                       | {#kb git::Push}                       |
330| {#action git::ForcePush}                  | {#kb git::ForcePush}                  |
331| {#action git::Pull}                       | {#kb git::Pull}                       |
332| {#action git::PullRebase}                 | {#kb git::PullRebase}                 |
333| {#action git::Fetch}                      | {#kb git::Fetch}                      |
334| {#action git::Diff}                       | {#kb git::Diff}                       |
335| {#action git::Restore}                    | {#kb git::Restore}                    |
336| {#action git::RestoreFile}                | {#kb git::RestoreFile}                |
337| {#action git::Branch}                     | {#kb git::Branch}                     |
338| {#action git::Switch}                     | {#kb git::Switch}                     |
339| {#action git::CheckoutBranch}             | {#kb git::CheckoutBranch}             |
340| {#action git::Blame}                      | {#kb git::Blame}                      |
341| {#action git::StashAll}                   | {#kb git::StashAll}                   |
342| {#action git::StashPop}                   | {#kb git::StashPop}                   |
343| {#action git::StashApply}                 | {#kb git::StashApply}                 |
344| {#action git::ViewStash}                  | {#kb git::ViewStash}                  |
345| {#action editor::ToggleGitBlameInline}    | {#kb editor::ToggleGitBlameInline}    |
346| {#action editor::ExpandAllDiffHunks}      | {#kb editor::ExpandAllDiffHunks}      |
347| {#action editor::ToggleSelectedDiffHunks} | {#kb editor::ToggleSelectedDiffHunks} |
348
349> Not all actions have default keybindings, but can be bound by [customizing your keymap](./key-bindings.md#user-keymaps).
350
351## Git CLI Configuration
352
353If 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`:
354
355```sh
356git config --global core.editor "zed --wait"
357```
358
359Or add the following to your shell environment (in `~/.zshrc`, `~/.bashrc`, etc):
360
361```sh
362export GIT_EDITOR="zed --wait"
363```