2

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

Rhonda
  • 93
  • 9

1 Answers1

1

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.

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250