yc6q3a
Last Updated: February 25, 2016
·
1.498K
· mrako
4fe949ea9ee7c0bc5eb4bf3e17b09d75

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.

Say Thanks
Respond

3 Responses
Add your response

2822
1900150 10203074354438338 1015529188 n

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. :)

over 1 year ago ·
2824
4fe949ea9ee7c0bc5eb4bf3e17b09d75

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

over 1 year ago ·
15350
Img 20140216 114434

Some in mine configuration, but I really use few of them.

over 1 year ago ·