Git rebase auto abort on conflict

Viewed 183

I would like to configure git in a way to get the best of these both options, which are unfortunately mutually exclusive:

[pull]
    ff = only
    rebase = true

Basically, I want to automatically rebase when pulling, but if there are conflicts, the rebase should be aborted.
This way, if I update in the background, my repository always stays in a valid state.

1 Answers

After some fiddling, I concluded with the following shell alias:

[alias]
    l = !git pull --rebase --autostash || (>&2 echo "Error - aborting rebase!" && git rebase --abort)

It pulls and rebases, putting all local changes on top of the remote branch. If there is an error, the rebase is aborted and everything is back to the previous state. There are rare cases where the command fails not because of a rebase conflict, but this merely causes the abort to error as well and doesn't create any invalid state.

This is now my preferred way of updating from remotes, and if something goes wrong, I can still use the default pull command.
If anyone has a more native suggestion, I am still all ears!

Related