Skip to content

Instantly share code, notes, and snippets.

@daveslutzkin
Last active December 31, 2015 11:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save daveslutzkin/7981186 to your computer and use it in GitHub Desktop.
Save daveslutzkin/7981186 to your computer and use it in GitHub Desktop.
#!/bin/bash
# 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
fi
local_ref=$(git symbolic-ref -q HEAD)
local_branch="${local_ref#refs/heads/}"
remote_ref=$(git config "branch.$local_branch.merge")
remote_branch="${remote_ref#refs/heads/}"
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
fi
git merge --ff-only ${remote}/${remote_branch}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment