Aliases in Git
Did you know you can create git aliases almost the same way as you would create your shell aliases?
Global Aliases
To create global aliases type git config --global alias.<alias> <command>
The aliases will be saved to the file ~/.gitconfig
In my dotfiles I've additionally included an alias for git: alias g="git"
to make git status, add, commit and push very short:
g s
g a <filename>
g c -m "the commit message"
g p
Local Aliases
To create local aliases, such as a master-to-production merge, all you need to do is to create the alias without --global flag,or add the alias to the local .git/config
git config alias.production-merge "\!git checkout production;git merge master --no-ff;git checkout master"
Now you can just run git production-merge
to do the magic.
Written by Marko Klemetti
Related protips
2 Responses
You could have aliased the 'merge' command in git itself, no need to make the alias at your dotfiles. Just use the bang:
git config --global alias.merge "!git checkout production;git merge master --no-ff;git checkout master"
Then you just call git merge
and you're good to go. :)
Thanks! Cool idea - although I wouldn't make it a global, but rather a local alias.
I'll make the change to my dotfiles and update the protip. :D