A random collection of Git commands I've needed at some point or other.
Using Vim as the editor for commit messages
Instead of using the
-m flag to instroduce the message, as in:
git commit -m "first commit"
One can simply use:
and then a Vim window will open, into which one can type
and then save and exit using:
:wq, and then the commit will be as before, when using the
In order to enable the Vim editor to be associated with Git (because it does not seem to work by default on OSX), type the following into a terminal:
git config --global core.editor "vim"
which should do the trick. Source: this Stackoverflow post
A better git log experience
git log --oneline is great, it may be useful to have more information (time of commits, commit authors, etc). The following three options are worth trying out. To activate a Git alias, enter one of the following commands in a terminal:
git config --global alias.lgb "log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset%n' --abbrev-commit --date=relative --branches"
git config --global alias.lola "log --graph --all --decorate --oneline --abbrev-commit"
git config --global alias.lgo "log --all --pretty='%C(yellow)%h%Creset %C(auto)%d%Creset %s %C(cyan)%ci%Creset' --date-order --max-count=10"
Get the remote repo url
You're in a Git folder, and your remote is
origin/master. But you want to know what the Github/Bitbucket address is. In a terminal in your Git folder, type:
git remote -v
Source: this post.