โ† Back to DevBytes

Sublime Text Git Integration: Complete Guide

Sublime Text Git Integration: Complete Guide

Sublime Text is one of the most popular lightweight code editors among developers, known for its speed, simplicity, and powerful plugin ecosystem. While it doesn't ship with built-in version control features, you can transform it into a capable Git workspace with the right packages. This guide walks you through everything you need to know about integrating Git into Sublime Text, from installation to advanced workflows.

What Is Sublime Text Git Integration?

Sublime Text Git integration refers to the process of adding Git version control capabilities directly into the Sublime Text editor through packages and plugins. The most popular package for this purpose is GitSavvy, which provides a full-featured Git client inside Sublime Text. Another common option is the simpler Git package by kemayo. These plugins allow you to stage, commit, branch, merge, diff, and push without ever leaving your editor.

Why Git Integration Matters

Switching between your editor and a terminal or separate Git GUI wastes time and breaks your concentration. Integrated Git tooling offers several benefits:

Prerequisites

Before you begin, make sure you have the following installed and configured:

If you don't have Package Control installed, open the Sublime Text console with Ctrl+` (or Cmd+` on macOS) and paste the installation snippet from packagecontrol.io.

Installing GitSavvy

GitSavvy is the most comprehensive Git package for Sublime Text. To install it:

  1. Open the Command Palette with Ctrl+Shift+P (or Cmd+Shift+P on macOS).
  2. Type Package Control: Install Package and press Enter.
  3. Search for GitSavvy and select it.
  4. Wait for the installation to complete. You'll see a success message in the status bar.

Once installed, GitSavvy automatically detects Git repositories in your project folders and enables its features.

Core Git Operations

Opening the Git Status View

The status view is your command center for Git operations. Open it via the Command Palette:

GitSavvy: Status

Or assign a custom key binding in your Default (OS).sublime-keymap file:

[
  {
    "keys": ["ctrl+alt+s"],
    "command": "gs_show_status"
  }
]

The status view displays staged files, unstaged files, untracked files, and the current branch. You can navigate with arrow keys and use shortcuts to perform actions.

Staging and Unstaging Files

From the status view, you can stage files individually or in bulk:

Committing Changes

To commit your staged changes, press c in the status view. This opens a commit message editor. Write your message, then press Ctrl+Enter (or Cmd+Enter on macOS) to commit:

feat: add user authentication module

- Implement login and registration endpoints
- Add JWT token generation
- Include password hashing with bcrypt

You can also amend the last commit by pressing a in the status view, which lets you modify the previous commit message or add forgotten changes.

Viewing Diffs

GitSavvy provides multiple ways to view diffs:

The inline diff view highlights added lines in green and removed lines in red, making it easy to review changes before committing.

Branch Management

Creating and Switching Branches

Branch operations are accessible from the Command Palette or the status view:

GitSavvy: Checkout New Branch
GitSavvy: Checkout Branch
GitSavvy: Rename Branch
GitSavvy: Delete Branch

From the status view, press b to open the branch menu, where you can quickly switch between existing branches or create new ones.

Merging and Rebasing

To merge another branch into your current branch:

GitSavvy: Merge Branch

Select the branch you want to merge, and GitSavvy will perform the merge. If conflicts arise, GitSavvy highlights them in the editor with conflict markers, and you can resolve them directly:

<<<<<<< HEAD
const apiUrl = "https://api.production.example.com";
=======
const apiUrl = "https://api.staging.example.com";
>>>>>>> feature/staging-config

After resolving conflicts, stage the files and commit to complete the merge.

Working with Remotes

Pushing and Pulling

From the status view, you can push and pull with single key presses:

You can also use the Command Palette for more control:

GitSavvy: Push...
GitSavvy: Pull...
GitSavvy: Fetch...
GitSavvy: Fetch All

Managing Remotes

To add or remove remotes, use the Command Palette:

GitSavvy: Add Remote
GitSavvy: Remove Remote

Example remote configuration:

origin  https://github.com/username/repo.git (fetch)
origin  https://github.com/username/repo.git (push)
upstream  https://github.com/org/repo.git (fetch)
upstream  https://github.com/org/repo.git (push)

Viewing History and Logs

GitSavvy provides a graphical history view that shows commits, authors, dates, and changed files:

GitSavvy: Show History

In the history view, you can:

Inline Git Blame

GitSavvy can display blame information inline in your editor. Enable it with:

GitSavvy: Toggle Git Blame

This shows the author and commit hash for each line in the gutter, helping you understand when and why each line was last modified.

Customizing GitSavvy

Settings File

GitSavvy is highly customizable through its settings file. Access it via Preferences > Package Settings > GitSavvy > Settings. Here's an example configuration:

{
  "diff_context": 3,
  "show_diff_persistent": true,
  "statusbar_enabled": true,
  "short_statusbar": true,
  "ignore_whitespace": false,
  "commit_on_save": false,
  "show_in_status_bar": ["branch", "ahead_behind", "modified"],
  "git_path": "/usr/bin/git"
}

Custom Key Bindings

You can map frequently used Git commands to convenient shortcuts. Add these to your keymap file:

[
  {
    "keys": ["ctrl+alt+g", "ctrl+alt+s"],
    "command": "gs_show_status"
  },
  {
    "keys": ["ctrl+alt+g", "ctrl+alt+d"],
    "command": "gs_diff_current_file"
  },
  {
    "keys": ["ctrl+alt+g", "ctrl+alt+b"],
    "command": "gs_blame_current_file"
  },
  {
    "keys": ["ctrl+alt+g", "ctrl+alt+h"],
    "command": "gs_show_history"
  },
  {
    "keys": ["ctrl+alt+g", "ctrl+alt+c"],
    "command": "gs_commit"
  }
]

Using the Git Package (Alternative)

If you prefer a simpler, lighter-weight integration, the Git package by kemayo is a good alternative. It provides basic Git commands through the Command Palette without a dedicated UI:

Git: Add
Git: Commit
Git: Push
Git: Pull
Git: Diff
Git: Log
Git: Checkout

This package is ideal for developers who only need occasional Git operations and prefer running most commands in the terminal.

Best Practices

Write Meaningful Commit Messages

Follow conventional commit standards to keep your history clean and readable:

type(scope): subject

body

footer

Example:

fix(auth): resolve token expiration check

The JWT validation was comparing timestamps in different
timezones, causing premature token expiration for UTC+12 users.

Closes #342

Commit Frequently with Focused Changes

Each commit should address a single concern. Use GitSavvy's selective staging to commit related changes together rather than dumping all modifications into one commit.

Review Before Committing

Always use the diff view to review your changes before committing. This catches debug statements, console logs, and accidental changes that shouldn't be in the repository.

Use .gitignore Effectively

Keep your repository clean with a well-maintained .gitignore file:

# Dependencies
node_modules/
vendor/

# Build artifacts
dist/
build/
*.o
*.class

# Environment files
.env
.env.local

# Editor files
*.sublime-project
*.sublime-workspace
.sftp-config.json

# OS files
.DS_Store
Thumbs.db

Leverage Branches for Isolation

Create a new branch for every feature or bug fix. This keeps your main branch stable and makes code reviews easier:

GitSavvy: Checkout New Branch -> feature/user-profile

Keep Your History Clean

Use interactive rebasing to squash or reword commits before merging a feature branch. GitSavvy supports this through:

GitSavvy: Rebase...
GitSavvy: Interactive Rebase

Configure Your Git Identity

Make sure your Git identity is properly configured so commits are attributed correctly:

git config --global user.name "Jane Developer"
git config --global user.email "jane@example.com"

Troubleshooting Common Issues

GitSavvy Not Detecting Repository

If GitSavvy doesn't recognize your repository, ensure the project folder is added to your Sublime Text workspace via Project > Add Folder to Project. The repository root must be within one of these folders.

Git Command Not Found

If GitSavvy reports that Git is not found, specify the full path in settings:

{
  "git_path": "/usr/local/bin/git"
}

On Windows, use the full path with forward slashes:

{
  "git_path": "C:/Program Files/Git/bin/git.exe"
}

Slow Performance in Large Repositories

For large repositories, disable features you don't need, such as inline blame or the status bar widget:

{
  "statusbar_enabled": false,
  "show_diff_persistent": false
}

Conclusion

Integrating Git into Sublime Text through packages like GitSavvy transforms a lightweight editor into a powerful version control workspace. By bringing staging, committing, branching, diffing, and history browsing directly into your editor, you eliminate the friction of context switching and streamline your development workflow. Whether you choose the full-featured GitSavvy or the minimalist Git package, the key is to configure it to match your habits, learn the keyboard shortcuts, and follow Git best practices like focused commits and clean commit messages. With these tools and techniques in place, you can manage your entire version control workflow without ever leaving Sublime Text.

๐Ÿ›  Tools from DevBytes

Inventory Tracker Pro โ€” Excel inventory system, low-stock alerts ยท $19
AI Dev Kit for Mac โ€” local AI dev environment templates ยท $9.99
KeyMapper for Mac โ€” custom keyboard shortcut toolkit ยท $7.99

โ† Back to all articles