# Git

> Review changes, read diffs, stage, commit and sync from the Git sidebar.

<Kbd>⌘</Kbd> <Kbd>⇧</Kbd> <Kbd>G</Kbd> opens the Git sidebar in the right dock for the active worktree. Press it again to return to the center. Rexa runs the `git` command you have installed.

The sidebar header shows the branch, with three faces below it:

- **Changes:** what is modified in the worktree, ready to stage and commit.
- **Compare:** what this branch changed since it left its base.
- **History:** the branch's commits.

The right end of the strip shows ahead/behind counts, **Sync**, **Publish** for a branch with no upstream, and the branch's pull request.

## Changes

Files sit in sections: **Conflicts** during a merge, **Staged**, and **Changes** for unstaged and untracked files. Each section shows a count and line totals.

- **Click a file** to open its diff in a center tab. Double-click keeps the tab.
- **Hover a file** for Open file, Discard and Stage or Unstage.
- **Right-click a file** for more: stash, copy path, reveal in Finder.
- **Right-click a section header** to stage, unstage, stash or discard everything in it.

View the list as **Grouped** by folder (the default), a **Tree** or a flat **List** with the palette commands **rexa: view changes as list / as tree / grouped**.

<Callout type="warning">
  Discard always asks first. It restores tracked files and deletes untracked ones. Discarding an untracked folder deletes the whole folder.
</Callout>

## Commit

Type the message in the box under the list and press <Kbd>⌘</Kbd> <Kbd>↵</Kbd> or **Commit**. Only staged changes are committed; nothing is staged for you.

Amend, sign-off and commit signing are not available. Use a terminal for those.

## Diffs

A file's diff shows the whole file with changes marked in place. The tab title says `(Index)` for staged changes and `(Compare)` for a branch comparison.

| Action                       | How                                                      |
| ---------------------------- | -------------------------------------------------------- |
| Next / previous change       | Strip arrows                                             |
| Split or inline layout       | `…` menu, or **rexa: toggle diff layout**                |
| Hide unchanged regions       | Strip toggle, or **rexa: toggle collapse unchanged**     |
| Go to definition             | <Kbd>F12</Kbd> or <Kbd>⌘</Kbd>-click                     |
| Open the file at a line      | Click the line number                                    |

- **Unstaged diffs are editable.** <Kbd>⌘</Kbd> <Kbd>S</Kbd> writes the change to the file. Staged and compare diffs are read-only.
- **Images** show previous and current side by side.
- **The layout you pick** becomes the default for new diffs (`git.diff_layout_tab`).

### Stage part of a file

Hover a change block in an unstaged diff and click **Stage**, or select lines and right-click → **Stage selection**. Save pending edits in the diff first. Renamed and binary files stage only as a whole.

### All changes in one view

**Open Changes** on a section header, a commit, or a pull request opens every file in one scrolling diff. Click a file's header bar to fold it. Commit and pull request diffs have a file panel to jump between files.

## Compare

Compare shows the merge base to head of the current branch: what a pull request would contain. The base defaults to the pull request's base branch, otherwise the remote's default branch. Pick either side from the branch lists, or swap them.

## History

History lists the branch's last 1,000 commits. Click a commit to open its changes; click its SHA to copy it. **Open Commit Graph** in the sidebar's right-click menu shows every branch in lanes.

## Sync, pull, push, publish

- **Sync** fetches, pulls, then pushes. It asks first until you choose **OK, Don't Show Again** (`git.confirm_sync`).
- **Pull** merges by default. Set `git.rebase_when_sync` to rebase instead.
- **Publish** pushes a branch that has no upstream and sets it. With several remotes, Rexa asks which one.
- **Push is never forced.**

The palette has **rexa: sync upstream**, **rexa: pull upstream**, **rexa: push upstream** and **rexa: fetch remote**.

Rexa never prompts for a password. On HTTPS remotes, it uses your `gh` or `glab` login once connected; otherwise configure a git credential helper.

## Merge conflicts

During a merge, a row above the commit box offers **Complete** and **Abort**. Abort asks first.

In a conflicted file's diff, each conflict has **Use ours**, **Use theirs** and **Use both**. <Kbd>⌘</Kbd> <Kbd>Z</Kbd> undoes a choice. When no markers remain, the diff offers **Stage the resolved file**.

Rexa detects merge conflicts only. Resolve rebase and cherry-pick conflicts in a terminal.

## In the editor

- **Gutter bars** mark changed lines against `HEAD`. Click a bar to show the removed lines inline.
- **Inline blame** shows the author, age and subject for the caret's line. Turn it off with `editor.inline_blame`.
- **Right-click → Copy As** copies a path, the commit SHA or message, or a permalink to the line on GitHub or GitLab.

## Git log

Every git command Rexa runs is recorded in the **Git Log** tab, with its output. Open it from the sidebar's right-click menu, or the log icon on an error message. It keeps the last 200 entries.

## Settings

<FieldGroup>
  <Field name="git.status_view" type="'grouped' | 'list' | 'tree'" default="'grouped'">How the Changes list is drawn.</Field>
  <Field name="git.diff_layout_tab" type="'split' | 'inline'" default="'split'">Layout for new diffs.</Field>
  <Field name="git.focus_first_change" type="boolean" default="true">Open diffs at the first change.</Field>
  <Field name="git.collapse_unchanged" type="boolean" default="false">Hide unchanged regions in diffs.</Field>
  <Field name="git.confirm_sync" type="boolean" default="true">Ask before Sync.</Field>
  <Field name="git.rebase_when_sync" type="boolean" default="false">Rebase instead of merge when pulling.</Field>
  <Field name="git.autofetch" type="boolean" default="false">Fetch in the background.</Field>
  <Field name="git.autofetch_period" type="number" default="180">Seconds between background fetches. Minimum 30.</Field>
  <Field name="git.remote_status" type="boolean" default="true">Show ahead/behind and pull request state in the sidebar.</Field>
  <Field name="editor.inline_blame" type="boolean" default="true">Show blame for the caret's line.</Field>
</FieldGroup>

## Not supported

- Creating, renaming, deleting or switching branches from the UI.
- Amend, signing, stash lists, clone and remote management.
- Staging from compare or combined diffs.
