I have a git setup with a shared repository. As I'm working on 2 PC's I push my personal branches.
I'm rebasing frequently with the develop branch so I need to force a push (git push -f origin feature). But when I want to pull a feature branch whith the forced changes I always get merge conflicts.
Is it possible to force a pull and overwrite the local files?
Important: If you have any local changes, they will be lost. With or without --hard option, any local commits that haven't been pushed will be lost. If you have any files that are not tracked by Git (e.g. uploaded user content), these files will not be affected.
The reason for error messages like these is rather simple: you have local changes that would be overwritten by the incoming new changes that a "git pull" would bring in. For obvious safety reasons, Git will never simply overwrite your changes.
There are two Git commands a developer must use in order to discard all local changes in Git, remove all uncommited changes and revert their Git working tree back to the state it was in when the last commit took place. The commands to discard all local changes in Git are: git reset –hard. git clean -fxd.
If you're wanting to just get to the state that you were at on the other machine when you force pushed, just reset --hard
to the head that you want:
$ git fetch
$ git reset --hard origin/<yourbranch>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With