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 currently offers a set of fundamental Git features, with support coming in the future for more advanced ones, like conflict resolution tools, line by line staging, and more.
  9
 10Here's an overview of all currently supported features:
 11
 12- Committing
 13- Staging, pushing, pulling, and fetching
 14- Project Diff: A multibuffer view of all changes
 15- Diff indicators in buffers and editor scrollbars
 16- Inline diff toggle and reverts in the editor for unstaged changes
 17- Git status in the Project Panel
 18- Branch creating and switching
 19- Git blame viewing
 20
 21## Git Panel
 22
 23The Git Panel gives you a birds-eye view of the state of your working tree and of Git's staging area.
 24
 25You can open the Git Panel using {#action git_panel::ToggleFocus}, or by clicking the Git icon in the status bar.
 26
 27In 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.
 28
 29Zed monitors your repository so that changes you make on the command line are instantly reflected.
 30
 31## Project Diff
 32
 33You 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.
 34
 35All of the changes displayed in the Project Diff behave exactly the same as any other multibuffer: they are all editable excerpts of files.
 36
 37You can stage or unstage each hunk as well as a whole file by hitting the buttons on the tab bar or their corresponding keybindings.
 38
 39<!-- Add media -->
 40
 41## Fetch, push, and pull
 42
 43Fetch, 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}.
 44
 45## Staging Workflow
 46
 47Zed has two primary staging workflows, using either the Project Diff or the panel directly.
 48
 49### Using the Project Diff
 50
 51In 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}).
 52
 53Similarly, 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}).
 54
 55### Using the Git Panel
 56
 57From 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.
 58
 59<!-- Show a set of changes with default staged -->
 60
 61Entries 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}.
 62
 63<!-- Add media -->
 64
 65## Committing
 66
 67Zed offers two commit textareas:
 68
 691. The first one is available right at the bottom of the Git Panel. Hitting {#kb git::Commit} immediately commits all of your staged changes.
 702. 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.
 71
 72### Undoing a Commit
 73
 74As 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.
 75In there, you can use the "Uncommit" button, which performs the `git reset HEADˆ--soft` command.
 76
 77## AI Support in Git
 78
 79Zed currently supports LLM-powered commit message generation.
 80You 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.
 81
 82> Note that you need to have an LLM provider configured for billing purposes, either via your own API keys or trialing/paying for Zed's hosted AI models. Visit [the AI configuration page](./ai/configuration.md) to learn how to do so.
 83
 84You can specify your preferred model to use by providing a `commit_message_model` agent setting. See [Feature-specific models](./ai/agent-settings.md#feature-specific-models) for more information.
 85
 86```json [settings]
 87{
 88  "agent": {
 89    "version": "2",
 90    "commit_message_model": {
 91      "provider": "anthropic",
 92      "model": "claude-3-5-haiku"
 93    }
 94  }
 95}
 96```
 97
 98<!-- Add media -->
 99
100More advanced AI integration with Git features may come in the future.
101
102## Git Integrations
103
104Zed integrates with popular Git hosting services to ensure that Git commit hashes and references to Issues, Pull Requests, and Merge Requests become clickable links.
105
106Zed currently supports links to the hosted versions of
107[GitHub](https://github.com),
108[GitLab](https://gitlab.com),
109[Bitbucket](https://bitbucket.org),
110[SourceHut](https://sr.ht) and
111[Codeberg](https://codeberg.org).
112
113Zed also has a Copy Permalink feature to create a permanent link to a code snippet on your Git hosting service.
114These links are useful for sharing a specific line or range of lines in a file at a specific commit.
115Trigger this action via the [Command Palette](./getting-started.md#command-palette) (search for `permalink`),
116by creating a [custom key bindings](key-bindings.md#custom-key-bindings) to the
117`editor::CopyPermalinkToLine` or `editor::OpenPermalinkToLine` actions
118or by simply right clicking and selecting `Copy Permalink` with line(s) selected in your editor.
119
120## Diff Hunk Keyboard Shortcuts
121
122When viewing files with changes, Zed displays diff hunks that can be expanded or collapsed for detailed review:
123
124- **Expand all diff hunks**: {#action editor::ExpandAllDiffHunks} ({#kb editor::ExpandAllDiffHunks})
125- **Collapse all diff hunks**: Press `Escape` (bound to {#action editor::Cancel})
126- **Toggle selected diff hunks**: {#action editor::ToggleSelectedDiffHunks} ({#kb editor::ToggleSelectedDiffHunks})
127- **Navigate between hunks**: {#action editor::GoToHunk} and {#action editor::GoToPreviousHunk}
128
129> **Tip:** The `Escape` key is the quickest way to collapse all expanded diff hunks and return to an overview of your changes.
130
131## Action Reference
132
133| Action                                    | Keybinding                            |
134| ----------------------------------------- | ------------------------------------- |
135| {#action git::Add}                        | {#kb git::Add}                        |
136| {#action git::StageAll}                   | {#kb git::StageAll}                   |
137| {#action git::UnstageAll}                 | {#kb git::UnstageAll}                 |
138| {#action git::ToggleStaged}               | {#kb git::ToggleStaged}               |
139| {#action git::StageAndNext}               | {#kb git::StageAndNext}               |
140| {#action git::UnstageAndNext}             | {#kb git::UnstageAndNext}             |
141| {#action git::Commit}                     | {#kb git::Commit}                     |
142| {#action git::ExpandCommitEditor}         | {#kb git::ExpandCommitEditor}         |
143| {#action git::Push}                       | {#kb git::Push}                       |
144| {#action git::ForcePush}                  | {#kb git::ForcePush}                  |
145| {#action git::Pull}                       | {#kb git::Pull}                       |
146| {#action git::Fetch}                      | {#kb git::Fetch}                      |
147| {#action git::Diff}                       | {#kb git::Diff}                       |
148| {#action git::Restore}                    | {#kb git::Restore}                    |
149| {#action git::RestoreFile}                | {#kb git::RestoreFile}                |
150| {#action git::Branch}                     | {#kb git::Branch}                     |
151| {#action git::Switch}                     | {#kb git::Switch}                     |
152| {#action git::CheckoutBranch}             | {#kb git::CheckoutBranch}             |
153| {#action git::Blame}                      | {#kb git::Blame}                      |
154| {#action editor::ToggleGitBlameInline}    | {#kb editor::ToggleGitBlameInline}    |
155| {#action editor::ExpandAllDiffHunks}      | {#kb editor::ExpandAllDiffHunks}      |
156| {#action editor::ToggleSelectedDiffHunks} | {#kb editor::ToggleSelectedDiffHunks} |
157
158> Not all actions have default keybindings, but can be bound by [customizing your keymap](./key-bindings.md#user-keymaps).
159
160## Git CLI Configuration
161
162If 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`:
163
164```sh
165git config --global core.editor "zed --wait"
166```
167
168Or add the following to your shell environment (in `~/.zshrc`, `~/.bashrc`, etc):
169
170```sh
171export GIT_EDITOR="zed --wait"
172```