Use rebase option whenever you pull from remote repository. Please follow the below steps,
- Commit your changes – It will create a new commit in your local.
- Now do
git pull --rebase <remote-name> <branch-name>. - Basically the rebase take out your commits that you committed on the current branch HEAD as a patch. Then it will apply all the remote commits on top of HEAD and then applies your commits on top of it.
- So best practice is to commit changes then pull remote commits by using rebase option.