If you are sure that you want to discard your local history, then see the other answers about git reset
and git branch -f
.
An alternative, that may be safer if you're not 100% sure that you don't have important local changes (or when you do know that you have important local commits that you don't want to discard) is to use git rebase
:
git checkout tracking-branch
git pull --rebase
Git will automatically notice which patches have already been applied upstream when the patch to apply is identical to the patch introduced by an upstream commit. When some patches have been rewritten, you may get some conflicts but then you can check manually whether the patch is actually to be skipped, and skip it manually with git rebase --skip
.