This is the overdue second post, in my series of Git tips for both new and experienced Git users. Some are commands I use, but not often enough to remember the syntax. Others are config changes I like to make to my environment.
The List
The full list of my Git tips is here.
What is an interactive rebase?
Rebasing is a powerful and advanced Git concept. I won't write too much about it here, as others have covered it already, but in essence it allows you to re-write the history of your repository.
Why would anyone want to do this? Rebasing can be used to clean up your commit history on a branch before pushing it. You may want to squash some commits or alter your commit messages for example. It is very important to only rebase branches which you haven't shared with others yet.
It is interactive because Git will open a text editor to ask for input. The default editor is VIM. VIM is a fine editor if you know how to use it, but I prefer to use Sublime Text.
The Command
Open a command prompt and type the following command:
git config --global core.editor "'{path to editor}' -n -w"
Sublime Text
For Sublime Text on Windows, this is the command:
git config --global core.editor "'C:\Program Files\Sublime Text 3\subl.exe' -n -w"
What does this command do?
git config
is used to set global and repository settings.core.editor
is the setting which tells Git which editor to use.-n
tells Git to open a new editor window. Omit this flag you want Git to reuse the Sublime window you already have open.-w
tells Git to wait until the commit message is saved.
Atom
For Atom on Windows, this is the command:
git config --global core.editor "atom.cmd --wait"
Notepad++
For Notepad++, run this command:
git config --global core.editor "'C:\Program Files\Notepad++\notepad++.exe' -nosession -notabbar"
VS Code
For VS Code, run this command:
git config --global core.editor "code --wait"
References
- http://stackoverflow.com/questions/22631863/setting-up-sublimetext-3-as-git-commit-text-editor
- https://github.com/atom/atom/issues/12032
- https://git-scm.com/book/en/v2/Customizing-Git-Git-Configuration
- https://git-scm.com/docs/git-rebase
- http://docs.notepad-plus-plus.org/index.php/Command_Line_Switches