Skip to content

Instantly share code, notes, and snippets.

@pda pda/git-ff
Created May 12, 2010

What would you like to do?
# Attempts to fast-forward the current local branch to its remote tracked branch.
# Safely refuses if there is no remote tracking, or if a fast-forward is not possible.
# @author Paul Annesley
if [ -n "$(git merge --ff-only 2>&1 | grep 'unknown option')" ]; then
echo "Your git doesn't seem to support --ff-only... try git 1.7+"
exit 1
local_ref=$(git symbolic-ref -q HEAD)
remote_ref=$(git config "branch.$local_branch.merge")
remote=$(git config "branch.$local_branch.remote")
if [ -z $remote_branch ] || [ -z $remote ]; then
echo "Local branch '$local_branch' not tracked against a remote."
exit 1
git merge --ff-only ${remote}/${remote_branch}

This comment has been minimized.

Copy link
Owner Author

commented Aug 28, 2014

This no longer works as of git 2.1:

"git merge" without an argument, even when there is an upstream defined for the current branch, refused to run until merge.defaultToUpstream is set to true. Flip the default of that configuration variable to true.

It's not worth fixing, because it can be replaced by an ff alias for merge --ff-only. That wasn't possible four year ago when this was written.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.