Back to Git & Dev Tools
2026-01-189 min read

Git in Sublime Text

Learn Git in Sublime Text step by step with clear examples and exercises.

Title: Mastering Git in Sublime Text - A full guide for Developers

Why This Matters

Git is an essential tool for developers, enabling collaboration, version control, and efficient code management. Integrating Git with a graphical user interface (GUI) like Sublime Text enhances productivity and streamlines workflows. This lesson will guide you through setting up Git in Sublime Text, understanding common mistakes, and providing practice questions to help you master this essential skill.

Git allows developers to track changes made to their codebase, collaborate with other team members, and maintain a history of modifications. By learning to use Git effectively within the popular Sublime Text editor, you'll be able to manage your projects more efficiently and minimize errors during development.

Prerequisites

Before diving into Git in Sublime Text, it is essential to have a basic understanding of:

  1. Git fundamentals (branches, commits, merges)
  2. Familiarity with the command line (optional but recommended for troubleshooting)
  3. Sublime Text editor basics (installation, plugins)
  4. Basic knowledge of version control concepts and how they apply to software development projects

Git Fundamentals

To ensure you have a solid foundation in Git, consider reviewing the following resources:

Core Concept

Installing Git and Sublime Text

First, make sure you have Git installed on your system. You can download it from Git's official website. For Sublime Text, visit its official site to download the latest version: Sublime Text 3 Download for Windows, MacOS, and Linux

Installing Git plugin for Sublime Text

To integrate Git with Sublime Text, you'll need a plugin called "GitGutter." Install it by following these steps:

  1. Open Sublime Text and go to the menu bar.
  2. Navigate to Preferences > Package Control > Install Package.
  3. Search for "GitGutter" in the search bar and install it.

Configuring Git for Sublime Text

Now, let's configure Git for use with Sublime Text:

  1. Open a terminal window (Command Prompt on Windows, Terminal on MacOS/Linux) next to your project folder.
  2. Run the following command to initialize Git in your project folder: git init
  3. To link your project to an existing repository or create a new one, use the following commands:
  • For existing repositories: git remote add origin
  • For new repositories (assuming you've already committed some files): git init; git add .; git commit -m "Initial commit"; git remote add origin ; git push -u origin master
  1. To enable GitGutter, go to Preferences > Settings > User and paste the following configuration:
{
"git": {
"autosync": true,
"autoupdate": true,
"ignore_whitespace": false,
"ignore_space_at_eol": false,
"ignore_space_change": false,
"ignore_content_changes": false
}
}

Navigating and Managing Git in Sublime Text

With GitGutter installed, you can now view the status of your files, stage changes, commit, and push directly from the editor. Here's how:

  1. To see the differences between your working copy and the last committed version, press Ctrl+Shift+G (Cmd+Shift+G on MacOS).
  2. Stage changes by clicking on the +/- icons next to each line in the GitGutter sidebar.
  3. Commit staged changes with Ctrl+B (Cmd+B on MacOS) or by navigating to Git > Commits > Commit in the menu bar.
  4. Push your commits to the remote repository using Ctrl+Shift+P (Cmd+Shift+P on MacOS) and typing "git push" in the command palette.

Understanding GitGutter Icons

!GitGutter Icons

  • Green +: New lines added but not staged.
  • Red -: Existing lines deleted but not staged.
  • Yellow ~: Modified lines that have been staged.
  • Blue |: Modified lines that haven't been staged.

Worked Example

For a hands-on experience, create a new Sublime Text project, add some files, make changes, stage them, commit, and push to a remote repository. Follow the steps outlined in the Core Concept section to complete this exercise.

Creating a New Project

  1. Open Sublime Text.
  2. Navigate to File > New Folder to create a new project.
  3. Name your project and click "Create."
  4. Add some files, such as index.html or app.js, by navigating to File > Save As.
  5. Make changes to the files to simulate modifications.
  6. Stage the changes by clicking on the + icons next to each modified line in the GitGutter sidebar.
  7. Commit the staged changes with Ctrl+B (Cmd+B on MacOS) or by navigating to Git > Commits > Commit in the menu bar.
  8. Enter a commit message, such as "Initial project setup," and click "Commit."
  9. Push your commits to the remote repository using Ctrl+Shift+P (Cmd+Shift+P on MacOS) and typing "git push" in the command palette.
  10. If prompted for a username and password, enter your GitHub credentials or follow the instructions for your chosen hosting service.

Common Mistakes

  1. Not initializing Git in your project folder: Always run git init before working on a new project or cloning an existing one.
  2. Forgetting to stage changes: Make sure you've staged all intended changes before committing to avoid losing any work.
  3. Ignoring whitespace changes: GitGutter has options for ignoring whitespace changes, but be careful not to enable them if you need to track these differences.
  4. Not configuring the correct repository URL: Ensure that the remote repository URL is set correctly when initializing or linking your local project.
  5. Not committing before pushing: Always commit your changes locally before pushing to the remote repository to avoid conflicts and data loss.
  6. Misunderstanding GitGutter icons: Familiarize yourself with the GitGutter icons to effectively navigate and manage your changes.
  7. Overlooking Sublime Text settings: Make sure you've enabled GitGutter by following the configuration steps outlined in this lesson.
  8. Not using version control for small projects: Even if a project seems small, it's still beneficial to use version control to track changes and collaborate with others.
  9. Not documenting commit messages: Clear and concise commit messages help other developers understand the context of your changes.
  10. Merging conflicts without resolving them manually: Merge conflicts should be resolved carefully to avoid introducing errors into the codebase.

Practice Questions

  1. What command do you run to initialize Git in a new project folder?
  • A: git init
  1. How can you stage all changes in your Sublime Text project for committing?
  • A: Click on the + icons next to each modified line in the GitGutter sidebar or use the "Stage" command from the Git menu.
  1. Describe the difference between staging changes and committing them in Git.
  • A: Staging changes selects which modifications will be included in the next commit, while committing saves those staged changes to the repository's history.
  1. What happens if you forget to commit changes before pushing to a remote repository?
  • A: Your local changes will not be saved in the remote repository, and other developers may overwrite your work if they pull updates without merging first.
  1. How do you view the differences between your working copy and the last committed version using GitGutter in Sublime Text?
  • A: Press Ctrl+Shift+G (Cmd+Shift+G on MacOS) to open a diff viewer showing the changes between your working copy and the last committed version.
  1. What are the GitGutter icons, and what do they represent?
  • A: Green +: New lines added but not staged.
  • Red -: Existing lines deleted but not staged.
  • Yellow ~: Modified lines that have been staged.
  • Blue |: Modified lines that haven't been staged.
  1. What should you do if you encounter issues or errors while setting up Git with Sublime Text?
  • A: Consult online resources, tutorials, or reach out to the community for help. Stack Overflow, Git's official documentation, and the Sublime Text forum are good places to start.
  1. How can you revert changes made to a file in your project using GitGutter?
  • A: Click on the - icon next to each modified line in the GitGutter sidebar or use the "Revert" command from the Git menu.
  1. What is the purpose of the git init command, and when should it be run?
  • A: The git init command initializes a new Git repository in your project folder, creating a .git directory that contains all necessary files for version control. It should be run before working on a new project or cloning an existing one.
  1. Describe how to link your local Git repository to a remote repository on GitHub or another hosting service.
  • A: To link your local Git repository to a remote repository, navigate to the terminal window next to your project folder and run git remote add origin , where `` is the URL of the remote repository you want to push to. If you're pushing to GitHub, you can find the URL by navigating to the repository on GitHub's website and clicking the "Code" button.

FAQ

  1. Why should I use Git with Sublime Text?
  • Using Git in Sublime Text allows for efficient version control, collaboration, and code management within a popular GUI editor.
  1. What is the purpose of the git init command?
  • The git init command initializes a new Git repository in your project folder, creating a .git directory that contains all necessary files for version control. It should be run before working on a new project or cloning an existing one.
  1. What are the GitGutter icons, and what do they represent?
  • Green +: New lines added but not staged.
  • Red -: Existing lines deleted but not staged.
  • Yellow ~: Modified lines that have been staged.
  • Blue |: Modified lines that haven't been staged.
  1. How can I stage all changes in my Sublime Text project for committing?
  • Click on the + icons next to each modified line in the GitGutter sidebar or use the "Stage" command from the Git menu.
  1. What happens if you forget to commit changes before pushing to a remote repository?
  • Your local changes will not be saved in the remote repository, and other developers may overwrite your work if they pull updates without merging first.
  1. How do I view the differences between my working copy and the last committed version using GitGutter in Sublime Text?
  • Press Ctrl+Shift+G (Cmd+Shift+G on MacOS) to open a diff viewer showing the changes between your working copy and the last committed version.
  1. What should I do if I encounter issues or errors while setting up Git with Sublime Text?
  • Consult online resources, tutorials, or reach out to the community for help. Stack Overflow, Git's official documentation, and the Sublime Text forum are good places to start.
  1. How can I revert changes made to a file in my project using GitGutter?
  • Click on the - icon next to each modified line in the GitGutter sidebar or use the "Revert" command from the Git menu.
  1. What is the difference between staging changes and committing them in Git?
  • Staging changes selects which modifications will be included in the next commit, while committing saves those staged changes to the repository's history.
  1. How do I link my local Git repository to a remote repository on GitHub or another hosting service?
  • To link your local Git repository to a remote repository, navigate to the terminal window next to your project folder and run git remote add origin , where `` is the URL of the remote repository you want to push to. If you're pushing to GitHub, you can find the URL by navigating to the repository on GitHub's website and clicking the "Code" button.
Git in Sublime Text | Git & Dev Tools | XQA Learn