Reputation: 5396
How do I open Sublime text from Git Bash in Windows? I tried adding the alias at the ~/.bashrc file but nothing worked. I was looking for something very easy but I could not find in the internet.
Upvotes: 28
Views: 45042
Reputation: 1
I followed what Cristiano Ferro did, and if you would like to commit a message with Sublime Text 3, paste this in your git.
Assuming the program is installed in Program Files
:
export GIT_EDITOR='C:\\Program\ Files\\Sublime\ Text\ 3\\sublime_text.exe'
After this, you can run git commit
, and it will open Sublime Text 3.
Upvotes: 0
Reputation: 5396
I am going to answer my own question. First, I created a .bash_profile
file under /Users/username directory. I have copied all my git aliases here. To access sublime text I added this alias:
alias subl="/c/Program\ Files/Sublime\ Text\ 2/sublime_text.exe"
I think the spaces after the backward slashes are important for formatting. If this doesn't work you will have to look where your sublime_text.exe file situated at and put the path after formatting as above. Now in the git bash command line just type
subl .
to open the current directory in Sublime Text or the name of the file as
subl readme.md
to open it in Sublime Text. I also added other useful aliases in the .bash_profile
file like:
alias gc="git commit -m"
alias ga="git add ."
alias gl="git log"
alias gs="git status"
So in your git bash command prompt you can simply type
gs ##for git status
gl ##for git log, etc
I hope this will help someone.
Upvotes: 41
Reputation: 21
One of the problems I had was that I had to use backslashes \
in the path of the directory instead of normal slashes /
, like the everyone here is using. Then I had to escape backslashes using double backslash \\
. So, in my case I wrote the path like this:
alias subl='C:\\Program\ Files\\Sublime\ Text\ 3\\sublime_text.exe'
Upvotes: 2
Reputation: 658
Locate the folder where Sublime Text is installed. Here I'am taking an example of Sublime Text 3 which is installed in C:/Program Files. For many users it is present in C:/Program Files (x86).
Run the following command (based upon your requirement):
echo 'alias subl="/c/Program\ Files/Sublime\ Text\ 3/sublime_text.exe"'>> ~/.bashrc
Or
echo 'alias subl="/c/Program\ Files\ \(x86\)/Sublime\ Text\ 3/sublime_text.exe"'>> ~/.bashrc
Try Closing and Re-Opening Git-Bash. If it works, then you're done.
Otherwise, read this documentation from Udacity.
Upvotes: 1
Reputation: 333
Create .bash_profile
file under C:\Users\YourUserName\
and add the following line in the file:
alias 'subl="/c/Program Files/Sublime Text 3/subl.exe"'
Upvotes: 14
Reputation: 161
I had the same issue launching Sublime Text 3 form Git Bash.
I ran the following command (my OS was windows 7 and Sublime Text 3 was located in the "C:\Program Files\Sublime Text 3
" directory) :
echo 'alias subl="/C/Program\ Files/Sublime\ Text\ 3/sublime_text.exe
"' >> ~/.bashrc
Close Git Bash and Open it again.
Upvotes: 2
Reputation: 193
I was having some difficulty getting this to work for me as well despite all the answers listed here. I found that modifying my .bashrc file through VIM as suggested here fixed the problem for me. I'm using Git bash on windows 10.
First I opened bash to my home directory, you can use cd~ to make sure you're in the right place.
Then, I created my .bashrc file using:
touch .bashrc
Then I went to edit that file using:
vim .bashrc
press the i
key to enter insert mode
enter:
alias subl='C:/Program\ Files/Sublime\ Text\ 3/sublime_text.exe'
As noted by pretty much everyone else this will have to be the correct path to your sublime_text.exe location. A quick search of your C:\ drive for sublime_text.exe should yield this location.
now hit esc
to exit input mode
Enter :
w
q
enter
to save and exit vim
exit bash and reopen to apply the new settings
Entering subl
should open sublime text editor now.
I had tried editing my .bashrc file with wordpad and sublime text itself, but for some reason editing in vim and making sure all the forward slashes and backslashes were correct as noted above worked for me.
I had found a rogue ^M character after my file path using some of the other methods which I think might have been complicating things as well. deleting this character in vim also fixed the problem after using SawyerDoesStuff's solution.
Thanks for letting me revive an older post and I hope this helps.
Upvotes: 1
Reputation: 61
I'm pretty new to this stuff and to git and sublime text. I'm taking the Udacity course on git right now, and was unable to get git bash to open sublime text.
I kept getting bash: subl: C:/Program command not found
or something like that
I found my problem ended up being I had my slashes going the incorrect way, and I found if you have spaces in your file path, you have to add a slash everytime you have a space and it will fix the problem.
I ended up typing
echo 'alias subl="C:/Program\ Files/Sublime\ Text\ 3/subl.exe"' >> ~/.bashrc
then subl
and sublime text was opened.
My original file path was-
C:\Program Files\Sublime Text 3
so make sure you have your slashes going the correct way, and if you have spaces in your file path, to add the necessary slash after a word.
I'm on windows 10 using sublime text 3 and git bash
Hopefully this saves someone else a lot of time.
Upvotes: 6
Reputation: 1637
I added this to my C:\Users\username\.bashrc file:
export PATH="$PATH:/c/Program Files/Sublime Text 3"
Save the file. Then in Git Bash, type
which subl
to prove it works.
Upvotes: 4
Reputation: 159
A Better Solution:
The updated version of sublime text 3(Build 3065) brings this feature as "subl.exe" which was "subl" in mac os.
How to use:
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 variables)
Upvotes: 12
Reputation: 675
Create a text file called subl (with no extension) with the following content:
#!/bin/sh
"C:\Program Files\Sublime Text 2\sublime_text.exe" $1 &
Copy it into the C:\Program Files (x86)\Git\bin folder. 32bit Copy it into the C:\Program Files\Git\usr\bin folder. 64bit
Now to open the file enter the following command on Windows Git Bash
subl text.txt
or
subl .
Upvotes: 4