For example, if I cloned a repository A to some other remote location (B) over ssh, edited in B, committed, then executed
git push A
When I go back to A, I see that it is now at the latest pushed revision, but it also has some changes staged – the direct opposite of that commit in B, actually. I usually work around it by using
git checkout -f master
but the “-f” flag makes me nervous – for example, there could be some useful changes staged, that I carelessly throw away by doing this checkout.
What am I doing wrong? Is there some better way of doing push/update?
The intended command would be “git pull” rather than the “git checkout”
If you have changes that are not committed, you should. This will save the changes that you have and get the new updates. Finally reapply the changes that you originally saved.
If you have local commits that you have not pushed yet, you can do. This will rewind your changes apply what was pushed and reapply the commits.
You can just do “git pull” with the commits but that will add a merge commit, that in my opinion dirties the history and can cause some problems.
I generally do not like the -force option for the reason that you stated. You don’t want to lose anything useful.