Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git pull needs to discard local files

Tags:

git

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?

like image 215
tom Avatar asked Oct 12 '10 17:10

tom


People also ask

Will git pull delete 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.

Does git pull discard local changes?

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.

How do you discard local changes and pulls from a remote?

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.


1 Answers

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>
like image 143
Amber Avatar answered Oct 30 '22 15:10

Amber