Are you looking for a quick fix to use your preferred editor in Git Bash and edit files directly from the Git command line by typing the command of your choice? Are you tired of seeing Git Bash crash each time it tries to open a file, as in case of merging conflicts for instance?
Here is how you do it in a few simple steps. For the story, I have configured it many times, but with each reset of my computer and/or OS, I lost my settings. Each time, I had to search again online, losing quite a bit of time.
Set your default git editor
1) Open Git
2) Find the path of your prefered editor (ex. C:/Program Files (x86)/Notepad++/notepad++.exe for the 64-bit version of Notepad++
3) Set your editor by typing the command below (you will have to replace the path in case you use anything different than Notepad++ installed the default way on a 64-bit version of Windows…)
git config --global core.editor "'C:/Program Files (x86)/Notepad++/notepad++.exe' -multiInst -notabbar -nosession -noPlugin
Set a customized command to open files with your preferred editor
1) Find the aliases configuration file of Git on your computer (for example, this is the path on my pc : C:\Program Files\Git\etc\profile.d\aliases.sh)
2) Open the
aliases.sh file in an appropriate editor
3) The aliases.sh file should look something like the one below, except for the “n++” and “gs” aliases already set 😉
screenshot of aliases.sh
4) Now add a line such as
alias n++='"C:/Program Files (x86)/Notepad++/notepad++.exe" $1' where “alias” HAS to be there, “n++” is the command of your choice (don’t use commands already used), “blablablabla.exe” is the path to your editor and “$1” is a variable which will contain whatever you put behind the command. For instance, if I type “n++ readme.md”, it launches the readme.md file in the notepad editor.
5) Restart Git in case it is open and enjoy your custom command!
Please remind that this works for me on Git Bash for Windows 64-bit.
Sources: This piece of advice comes from various sources such as Stackoverflow and the GitHowTo website. If you are new to Git, I strongly recommend Udacity’s introductory course, presented by Sarah Spikes and Caroline Buckey. They make an impressive job at explaining a quite arid topic such as Version control in a highly pedagogical and interactive way.