Reputation: 3114
Just before pushing the local changes to the remote repository, git always asks us to sync local branch with remote branch . For that to happen, I am doing git pull first, then commit the pulled changes and finally then push.
Problem with this approach is, git merges the pulled in files with my existing changes and in the future when I try to figure out what I had done on that particular commit, there will be no clear distinction between what I did and what pull merged.
I would like to have a clean history, that is my commits always should have/show only those changes that I add but not that were merged due to pull.
One solution for this problem I can think of is have two local branches for the given remote branch. (1) for your changes, (2) for syncing up with the remote and when one needs to push , sync the (2) with the remote first and then merge (1) with (2) and then push from (2)
Any other suggestions on how to have a clean history?
Upvotes: 1
Views: 331
Reputation: 10280
Before pushing to the remote repository (your local commits), you should do a
git fetch origin
to fetch all changes made to the repository (origin is just an example name). Afterwards, do a
git rebase origin/remote-branch
in order to rebase your local branch on top of the origin/remote-branch one.
If a file was changed both locally and on the repository, you will have to fix the merge issues here. If the rebase
finishes smoothly, you are ready to push:
git push origin local-branch
This will keep a clean straight git branch.
Upvotes: 3