NEVER DO a REBASE ON PUBLIC BRANCH.
Git merge is helped to merge branches.
In the Git merge post, we had already learned how developers merge it to the main branch, using the “git merge” command. But you could also use the “git rebase”.
You have a question,
What is the difference between “merge” and “rebase”?
The answer is what the final result will look like.
1) Merge: – Merge commit will be created.
2) Rebase: – The log history becomes linear and clean. There is no merge commit, when rebasing is complete, the log history looks like there was no branch. Every commit in the rebased branch has a different hash.
As the changes are the same, but due to different hash GIT will react respectively.
If you do git commit to the public branch, team members face a lot of conflict and error, because you commit hashes. It is preferable to use it on your separate branch.
- Switch to new branch.
- Do some changes.
- Using “gits status”, check the status of your file.
- Stage the file using the command.
git add newformpage.txt git commit -m "New Rebase - Check"
Let’s rebase it on the main branch. (We have to specify on which we would like to rebase)
git rebase main Successfully rebased and updated refs/heads/new-update-one.
Let’s Check the commit hash of our local commit.