Skip to main content

Sublime Merge includes a command line tool, smerge, to work with repositories on the command line. This can be used to open repositories, search, and merge files.

## Sublime Merge Command Line Usage

Sublime Merge includes a command line tool, `smerge`, to work with repositories
on the command line. This can be used to open repositories, search, and merge
files.

### Setup

#### Windows

Add `C:\Program Files\Sublime Merge` to your environment `%PATH%` variable.

#### macOS

You'll want to add a symlink (symbolic link) to `smerge`. Assuming you've placed
Sublime Merge in the Applications folder, and that you have a `~/bin` directory
in your path, you can run:

```bash
ln -s "/Applications/Sublime Merge.app/Contents/SharedSupport/bin/smerge" ~/bin/smerge
```

#### Linux

`smerge` should already be available by default. However, it won't be if you're
using a tarball, so you'll want to add a symlink to `sublime_merge` named
`smerge`:

```bash
ln -s /opt/sublime_merge/sublime_merge ~/bin/smerge
```

### Git Merge Tool Setup

The merge tool can be used to process merge conflicts within a Git repository
from the command line.

After configuring `smerge` using the instructions above, run the following from
the repository directory:

```bash
git config mergetool.smerge.cmd 'smerge mergetool "$BASE" "$LOCAL" "$REMOTE" -o "$MERGED"'
git config mergetool.smerge.trustExitCode true
git config merge.tool smerge
```

#### Git Merge Tool Usage

To invoke the merge tool, run:

```bash
git mergetool
```

> **Reference** [Sublime Merge Command Line Documentation](https://www.sublimemerge.com/docs/command_line)