Git is a distributed version control system. That means you can commit locally and after sometimes you can push those commits to online repository. But think about a situation where you are working on a project and committing some changes locally. After sometimes when you try to push your changes you got an error saying that your local copy is not updated. This is because from the time when you took the last update into your local copy since then some other developers pushed update to the online repository. So now you need to pull the update first, fix if there are any merge conflicts and then push your commits to online repository. But by doing so your project’s commit history become messy.
So what is the solution? There can be multiple solutions to this problem. The most easy solution is, before pushing your local changes to online repository, first do a git fetch operation to check is there are any incoming changes in the online repository? If there are some incoming changes then don’t merge those instead do a rebase operation. Rebase means you are putting your local changes on top of incoming changes from online repository. Also you need to fix in case of any conflicts. Then push your changes to online repository. In this way your project’s commit history is remain clean and linear.
git fetch origin git rebase origin/master git push origin master