christova

git

Git Merge vs. Rebase vs. Squash Commit! What are the differences?

When we ๐ฆ๐ž๐ซ๐ ๐ž ๐œ๐ก๐š๐ง๐ ๐ž๐ฌ from one Git branch to another, we can use โ€˜git mergeโ€™ or โ€˜git rebaseโ€™. The diagram above shows how the two commands work.

๐†๐ข๐ญ ๐Œ๐ž๐ซ๐ ๐ž

This creates a new commit Gโ€™ in the main branch. Gโ€™ ties the histories of both main and feature branches. Git merge is ๐ง๐จ๐ง-๐๐ž๐ฌ๐ญ๐ซ๐ฎ๐œ๐ญ๐ข๐ฏ๐ž. Neither the main nor the feature branch is changed.

๐†๐ข๐ญ ๐‘๐ž๐›๐š๐ฌ๐ž

Git rebase moves the feature branch histories to the head of the main branch. It creates new commits Eโ€™, Fโ€™, and Gโ€™ for each commit in the feature branch.

The benefit of rebase is that it has ๐ฅ๐ข๐ง๐ž๐š๐ซ ๐œ๐จ๐ฆ๐ฆ๐ข๐ญ ๐ก๐ข๐ฌ๐ญ๐จ๐ซ๐ฒ.

Rebase can be dangerous if โ€œthe golden rule of git rebaseโ€ is not followed.

๐“๐ก๐ž ๐†๐จ๐ฅ๐๐ž๐ง ๐‘๐ฎ๐ฅ๐ž ๐จ๐Ÿ ๐†๐ข๐ญ ๐‘๐ž๐›๐š๐ฌ๐ž Never use it on public branches!

#Git #git #gitmerge #gitrebase

Always try using git pull โ€”-rebasebefore a git pull. Hereโ€™s why:

#git