git - Why reset --hard seems to be always needed

79 views Asked by At

When working on two workstations (say one from the office, one from home) on the same git project, after committing/pushing from one and trying to pull from the other (say the next day), branch seems always to be out of sync after

git pull --all

and the solution proposed here is needed.

Why is that? (I never do a forced push as implied in the above post).

1

There are 1 answers

1
Animesh Sharma On

The safest way to handle git repositories from getting corrupted due to some dangling heads or forced push is to use the following:

git fetch
git rebase origin/your_branch

git pull by default fetches and then merges instead of rebasing.

Difference between merge and rebase can be found here: https://www.atlassian.com/git/tutorials/merging-vs-rebasing/conceptual-overview

What you should do now is remove the repo from both of your workstations(obviously after committing and pushing all the local changes). Clone it again. Create a local tracking branch for 'your_origin_branch'. And follow the above procedure to make changes henceforth.