Can “git pull” automatically stash and pop pending changes?

前端 未结 5 943
死守一世寂寞
死守一世寂寞 2020-11-21 23:41

I know how to solve this:

user@host$ git pull
Updating 9386059..6e3ffde
error: Your local changes to the following files would be overwritten by merge:
    f         


        
5条回答
  •  南旧
    南旧 (楼主)
    2020-11-22 00:19

    With Git 2.6+ you can use the following:

    alias gup='git -c rebase.autoStash=true pull --rebase'
    

    This --rebase makes git-pull use rebase instead of merge, so settings/options like --ff-only won't apply.

    I am using an alias to pull with --ff-only by default (git pull --ff-only), and can then use gup (from above) in case a fast-forward merge is not possible or there are stashed changes.

提交回复
热议问题