Write a git alias for fast forward that works in any tracking branch?

I would like to create an alias to do the following:

While working in master, I would like to git ffperform git merge --ff-only origin/master. But I need the same alias when you execute maintto execute git merge --ff-only origin/maint. Similarly for any other tracking branches. Is it possible?

+5
source share
3 answers

Claim to two other answers, but there is an easier way, assuming your branches track remote branches:

git pull --ff-only

Bonus: this will work even if your branches track repo branches other than origin, or track different branches. It is also very short.

+5

, :

[alias]
    ff = !sh -c 'branch=$(git symbolic-ref HEAD | cut -d '/' -f 3) && git merge --ff-only origin/$branch' -
+5

, :

git merge --ff-only origin/`git branch | grep "^\*" | cut -c 3-`

git branchall local branches are listed; grep "^\*"selects the current one (which has a prefix with an asterisk), and cut -c 3-cuts off the asterisk, leaving only the branded font. Backticks embed the output of this command, namely branchname, into the merge command.

+1
source

All Articles