git.md

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