git: hook for fast-forward switch on branch change?

Is there a hook script available somewhere that would do a fast-forward merge on branch switch? I have a repository where there are multiple branches, and I have to work on several on them. After a git pull which obviously merges the currently checked out branch it often happens to me that I see the following message when switching branches:

> git checkout master 
Switched to branch 'master'
Your branch is behind 'origin/master' by 10 commits, and can be fast-forwarded.
> 

I would like git to do that fast-forward merge for me automatically on branch change. I don't want it to unconditionally merge but only when a fast-forward is possible.

Thanks in advance for suggestions, Rhonda

Answers


I would suggest an alias rather than a hook, in oder to combine:

  • git pull
  • with one of the scripts detailed in "How can I fast-forward a single git commit, programmatically?" (but adapted in order to fast-forward all the way)

The question "Using Git when I want my branches to be always updated" references the script "git-fetch-and-fast-forward-all-branches.sh", which can be of interest here.


Need Your Help

Traversing a boost::ublas matrix using iterators

c++ boost matrix iterator ublas

I simply want to traverse a matrix from start to finish touching upon every element. However, I see that there is no one iterator for boost matrix, rather there are two iterators, and I haven't bee...

JavaScript Regex pull out only a number in an element

javascript jquery regex

How would one go about pulling out just a number in the text of an element? I want to set this as a variable.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.