If another developer made a change to the history of git
and then did git push -f
, git pull
it doesn't work for me.
How can I fetch the changes from the remote?
If another developer made a change to the history of git
and then did git push -f
, git pull
it doesn't work for me.
How can I fetch the changes from the remote?
The first step is to receive all the commits that are in the remote, for that do
I assume we are talking about
master
. If not, replacemaster
with the name of the branch you are working with.Reset
To point the local branches to the same commit that is on the remote, you have to use
git reset
.If you don't mind losing your local changes:
This will undo all your changes and bring back the same thing that is on the remote. From now on,
git push
andgit pull
they will work as usual.If you want to keep your changes local:
Instead of a hard reset, do a soft reset
You can apply your local commits on top of what's on the remote using
git rebase
This will run an
rebase
interactive mode, where you can choose how to apply your local commits that are not on the remote above theHEAD
current one.If the changes in the history deleted any commit that you have local, they will appear as commits pending to be applied again. If you don't want them to be applied, you'll have to delete them as part of the rebase.
Use
git command --help
for more details and examples of how to apply any of these commands.