My First Own Git Alias: Fast Forward Some Branch To Its Origin's (aka Remote's) HEAD

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!

enjoyed the post?

Tags:

git

Add comment

  Country flag

biuquote
  • Comment
  • Preview
Loading

About Oliver

shades-of-orange.com code blog logo I build web applications using ASP.NET and have a passion for javascript. Enjoy MVC 4 and Orchard CMS, and I do TDD whenever I can. I like clean code. Love to spend time with my wife and our children. My profile on Stack Exchange, a network of free, community-driven Q&A sites

About Anton

shades-of-orange.com code blog logo I'm a software developer at teamaton. I code in C# and work with MVC, Orchard, SpecFlow, Coypu and NHibernate. I enjoy beach volleyball, board games and Coke.