How many times the below thing happens to you? You have created or patch branch in your work hotfix You have pushed your commits to your work remote repo There has been a update in master leaving your branch out-of-sync with master. hotfix You will be forced to "Sync them" Now is the question? or ? git rebase git merge Though, is the keyword everyone uses and your managers will force you to rebase without knowing consequences. git rebase Simply, won't work. Will explain you why. git rebase takes all the commits from your branch and applies on the new branch out of master as if that commit was never made. git rebase hotfix hotfix It is like as if yourself Takes all the changes in the first commit of branch and then applies the changes to the corresponding files manually via a code editor and then you commit them like usual in a new branch cut out of master. hotfix temp You would repeat 1 for all the commits in your branch. hotfix And then you would delete the old branch and rename the branch as your branch hotfix temp hotfix automates the above steps with optimisations. You can read about in . git rebase git rebase here One thing you might have noticed that the old branch and new rebased branch are not the same, though their contents are. you can confirm them by . You will see the new datetimes and new hashids or commit ids compared to what you saw in the old . hotfix hotfix git log hotfix So, now when you try to push the changes to branch, you will get an error similar to, " . hotfix Updates were rejected because the tip of your current branch is behind its remote" This is completely understandable since both branches have different ids in their history and no commit in common except for the base commit out of master. And a normal cannot force the remote repo to override its branch. git push origin hotfix hotfix Most often, Your organization would have disabled , which lets u overwrite the branch. force-push hotfix Only working option u have is . git merge is a very simple command. It adds a merge commit on top of current in addition to resolving any conflicts. You can read about it in . git merge hotfix here Now, you can easily push the branch because you are pushing only a single commit on top of existing branch without changing old commit ids. hotfix So local is same as remote but one additional commit in local . But both share the same history except for that one additional commit. Thereby, Remote can fast-forward its remote branch. hotfix hotfix hotfix hotfixes TLDR; don't use , if u have pushed your branch to remote. Always use . git rebase git merge
Share Your Thoughts