# Git in Skink: diff, stage hunks, blame, commit, branches

> Use git without leaving Skink: gutter marks, stage or revert single hunks, inline blame, side-by-side diff, the git panel, commits, branches, stash, conflicts.

Source: https://skink.cc/tools/git/

Skink shows git changes next to the line numbers and lets you stage, revert, commit and switch branches without leaving the editor.

Press Alt+Shift+C for the git panel, Alt+Shift+D to peek at the change under the cursor, and `:diff` to compare the file side by side.

## Gutter marks

Next to the line numbers, compared with the index:

- **Green bar**: added lines
- **Blue bar**: modified lines
- **Red mark**: deleted lines
- **Dotted bar**: a change that is already staged

The scrollbar (the editor's last column) shows the same marks for the whole file.

Turn them off with `"gitgutter": false`.

## Working with hunks

| Key | Command | Does |
|---|---|---|
| Alt+Shift+N | `:nexthunk` | Next change |
| Alt+Shift+P | `:prevhunk` | Previous change |
| Alt+Shift+D | `:hunk` | Peek at the change: s stage, u unstage, r revert, Esc |
| Alt+Shift+S | `:stagehunk` | Stage the change at the cursor |
| | `:unstagehunk` | Unstage it |
| | `:reverthunk` | Put the index version back |

Clicking a gutter mark opens the same peek. Reverting is a normal edit, so Ctrl+Z undoes it.

**Hold Shift:**
The git keys are all Alt+Shift chords. The plain Alt versions do other things: Alt+N adds a cursor, Alt+S searches the project, Alt+C goes back to one cursor. If a chord does not reach Skink (macOS, tmux), type the command instead.

## Blame

- **Inline blame**: the faded author, date and summary at the end of the cursor line. On by default.
  - Alt+Shift+B (`:inlineblame`) toggles it.
  - `"inlineblame": false` turns it off for good.
- **`:blame`**: the whole file's blame in a tab. Enter on a line shows that commit.

## Diff

| Command | Shows |
|---|---|
| `:diff` | This file side by side against the index |
| `:diff HEAD` | This file against the last commit |
| `:diff all` | `git diff` of the whole tree, in a tab |

## The git panel

Alt+Shift+C (or `:gitstatus`, `:status`) opens the panel. In it:

| Key | Does |
|---|---|
| Enter | Open the file |
| s / u | Stage / unstage the file |
| S / U | Stage / unstage all |
| d | Discard changes (asks first; untracked files go to the trash) |
| c | Commit |
| C | Amend |
| b | Branches |
| z / Z | Stash / list stashes |
| g | Refresh |
| P / p / f | Push / pull / fetch |

Push, pull and fetch run in a terminal tab, so git asks for passwords, passphrases and keys itself.

Skink never handles your credentials.

## Committing

- `:commit MESSAGE` commits with that message.
- `:commit` alone opens a message tab. Write the message and save it (Ctrl+S) to commit. Closing the tab cancels.
- In the message tab, `:amend` toggles amending the last commit and `:signoff` toggles a Signed-off-by line.

To use Skink for `git commit` run from a shell too, see [Use Skink as your $EDITOR](https://skink.cc/tools/skink-as-editor/).

`:stage [PATH]` and `:unstage [PATH]` work on the current file or `PATH`.

## Branches and stash

| Command | Does |
|---|---|
| `:branches` | List local branches. Enter switches, D deletes (asks first) |
| `:branch NAME` | Create `NAME` and switch to it |
| `:switch NAME` (`:checkout`) | Switch to a branch |
| `:stash [MESSAGE]` | Stash the current changes |
| `:stashes` | List stashes. Enter applies, p pops, D drops |
| `:push`, `:pull`, `:fetch [ARGS]` | In a terminal tab |
| `:git ARGS` | Run any git command, output in a tab |

## Merge conflicts

| Command | Does |
|---|---|
| `:conflicts` | Open every conflicted file at its first marker |
| `:nextconflict` / `:prevconflict` | Move between conflict blocks |
| `:ours` / `:theirs` / `:both` | Resolve the block under the cursor |

Conflict blocks are tinted: ours green, theirs blue.

The first line of each block shows "Accept ours | theirs | both", and you can click one. Every resolution is undoable.

## In the file tree

File names are coloured by status:

- modified: yellow
- added: green
- untracked: teal
- conflicted: red
- ignored: grey

A folder takes the colour of its most serious file.

## Requirements

Skink runs your installed `git` for these features, so it needs `git` on your `PATH`.
