by Oliver
25. April 2017 10:34
Git aliases are a great way to save you some valuable keystrokes but also to stop remembering verbose syntax to do simple things.
One of these things I regularly do is fast-forwarding a local branch to the last commit of its remote tracking branch. There are – of course – several viable solutions to the problem but I like this one the most:
$> git fetch origin master:master
Yesterday, I've had enough of typing those same characters into my git console, so I finally set up the alias that I should have set up 3 years ago:
$> git config --global alias.ff '!git fetch origin $1:$1'
The first part of the command up to the apostrophe is simply how you define a git alias. The second part, wrapped in apostrophes, is the command that I want executed. Since I want to pass the branch name as an argument, I need to begin the command with an exclamation mark ! and write a full command line. Now I can simply call:
$> git ff master
I chose ff as the alias because I use it for fast-forwarding some branch that I'm not currently on.
Happy git'ting!