Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Development Tools Git Basics Branches Branching Out

fisnik poroshtica
fisnik poroshtica
14,154 Points

How to Open Sublime Text 3, from Git bash on windows?

How to Open Sublime Text 3, from Git bash on windows? instead of Notepad

step 1: Update sublime text (in sublimetext --> Help -> Check for Updates) step 2: Just navigate to your project folder through bash and type subl.exe which should open the folder in sublime text. (if you encounter "subl.exe" command not found, just add sublime's path eg: "C:\Program Files\Sublime Text 3" to your system path - Here's how to add path to environment

5 Answers

On Windows:

Open the Git command prompt

Enter the following:

subl.exe subl

This will open up a file called subl in sublime text 3

Enter the following in to the file:

!/bin/sh

"C:\Apps\Git\cmd\git.exe" $1 &

Change the filepath to your own one. eg: "C:\program files\Git\cmd\git.exe"

Click save.

You can now create files by typing subl newfile.html open file by typing subl newfile.html open the editor by typing subl

Doi! I wrote the path for git instead of sublime. Use instead:

!/bin/sh "C:\Apps\Sublime Text 3\subl.exe" $1 &

or

!/bin/sh

"C:\Program Files\Sublime Text 3\subl.exe" $1 &

Marcelo Marcon
Marcelo Marcon
2,893 Points

you can add on your .gitconfig, or by command line git config --global core.editor "sublime3" for example i use emacs -nw so, git config --global core.editor "emacs -nw"

Use visual studio code instead. It's a whole lot easier. And all you've got to type is :

code filename.extension

or if you wanna open all of the files in the current folder

code .

And if you wanna open a specific foler in a folder:

code foldername

That's it. I like visual studio code more than sublime text. (Only my personal preference).

Nafis Fuad :smile:

Cory Wallace
Cory Wallace
14,005 Points

I found none of the answers to work effectively. After spending three days coming the Interwebs, I stumbled across this from Stack overflow. Please feel free to review. Also, I am working on a Windows 7 Laptop, and this got me working in that environment.

here's a link to the original page on Stack Overflow:

https://stackoverflow.com/questions/2596805/how-do-i-make-git-use-the-editor-of-my-choice-for-commits/48212377#48212377

and here were the steps:

1. MAKE SURE SUBLIME IS INSTALLED UNDER C:\PROGRAM FILES

it is imperative that you place the program here while installing. The steps I will mentioned ONLY work when Sublime text 3 is installed there.

Here is a link to Sublime text 3: (https://www.sublimetext.com/3)

During installation, when asked where you would like to install, click "browse" and change the folder from "C:\Program Files (x86)" to "C:\Program Files" merely by selecting the "Program Files" folder and clicking on "Select Folder"

2. Create a Sublime Text project

we will be populating it with settings we want to use to edit git commit messages.

Open Sublime Text and go to "File" --> "New Window" to create a new anonymous project. Go to "Project" --> "Save Project As..." and choose a place to save it:

In Windows:

  1. save it in your home directory, ex: "C:\Users\MY_USER_NAME\" for the location "gitconfig.sublime-project" for the file name. The end result looks like this: "C:\Users\YOUR_USER_NAME.gitconfig.sublime-project"

  2. Now go to "Project" --> "Edit Project" to edit the project settings. Paste the following and "Ctrl+S" to save the settings:

{
    //For folder settings help see here: https://www.sublimetext.com/docs/3/projects.html 

    "folders":
    [

    ],

    "settings":
    {

        // Disables horizontal scrolling if enabled.
        // May be set to true, false, or "auto", where it will be disabled for
        // source code, and otherwise enabled.
        "word_wrap": false,

        // Set to a value other than 0 to force wrapping at that column rather than the
        // window width
        "wrap_width": 0,

        // Columns in which to display vertical rulers
        "rulers": [72, 50], //72 is recommended by git for commit message content, and 50 for commit titles

        // The number of spaces a tab is considered equal to
        "tab_size": 4,

        // Set to true to insert spaces when tab is pressed
        "translate_tabs_to_spaces": true,
    },

    "build_systems":
    [

    ]

}

Hit "Ctrl+S" to save, and close out of the Sublime Text editor project settings.

3. Set the editor to be used by git:

For Windows:

Open up a text editor (ex: Notepad, Notepad++, Sublime Text, Geany, etc), and create a file called ".bash_profile" in your home directory. Its path will be: "C:\Users\MY_USER_NAME.bash_profile"

Save the following into it:

alias subl="/c/Program\ Files/Sublime\ Text\ 3/subl.exe"

This creates a Git BASH alias called subl that we can now use in Git BASH for Windows, to easily open Sublime. This step is required for general Git BASH use.

Now you can call "subl" for instance, in Git BASH to open up a new Sublime Project in your current directory.

(MANDATORY):

Edit the .gitconfig file found in your home directory: "C:\Users\MY_USER_NAME.gitconfig" Using your script Editor of choice. Add the following to it:

" [core] editor = 'C:/Program Files/Sublime Text 3/subl.exe' --project ~/.gitconfig.sublime-project --wait " (Leave off quotations)

Hit "Ctrl+S" to save

4. Use it:

Close out of any open Git Bash windows. Open a New instance of Git bash Type "subl" (Leave off quotations) to start Sublime Text 3

Voula, It works!. This will open a Sublime Text editor window each time you type "Subl" into Git Bash.

Let me know if you have any questions or concerns, and keep up the good Coding :D

Blake Nelson
Blake Nelson
1,439 Points

I entered subl.exe subl to my bash and it says command not found. I also tried adding a file path to my usr/bin manually and i tried creating the path through git. I get a failed to create link error.

Blake Nelson
Blake Nelson
1,439 Points

I got it working. In Sublime text 3 the subl file isn't nested in any folders like Sublime Text 2. I just copied the subl file to my Git > usr > bin folder. In File Explorer under the "type" category, the subl file shows as an "Application".