DEV Community

Sabbir Siddiqui
Sabbir Siddiqui

Posted on

Git Rebase got you conflicted? Here's what you can do.

Let's say you're working with feature branches. I know Trunk based development is the way to go, but hear me out. If your team is using git flow, this will help you get out of a sticky situation.

If two people are collaborating on the same feature branch, and one person rebases the branch with main/master and pushes to origin, then the other person will face a load of conflicts when pulling the branch from origin (because of the new rebased commits). Here's how you can refresh your local branch completely:

  1. ๐ ๐ข๐ญ ๐Ÿ๐ž๐ญ๐œ๐ก ๐จ๐ซ๐ข๐ ๐ข๐ง ๐ญ๐ก๐ž-๐›๐ซ๐š๐ง๐œ๐ก (fetch branch from origin)
  2. ๐ ๐ข๐ญ ๐ซ๐ž๐ฌ๐ž๐ญ --๐ก๐š๐ซ๐ ๐จ๐ซ๐ข๐ ๐ข๐ง/๐ญ๐ก๐ž-๐›๐ซ๐š๐ง๐œ๐ก (reset local branch and point to origin)

This will update your local branch with the one in the remote. However, if you already made some changes in your own local branch and the other teammate has rebased it, here's what you can do

Scenario A -> If you already committed the changes, in that case you can just do this:

  1. ๐ ๐ข๐ญ ๐Ÿ๐ž๐ญ๐œ๐ก ๐จ๐ซ๐ข๐ ๐ข๐ง ๐ญ๐ก๐ž-๐›๐ซ๐š๐ง๐œ๐ก (fetch remote branch)
  2. ๐ ๐ข๐ญ ๐ซ๐ž๐›๐š๐ฌ๐ž ๐จ๐ซ๐ข๐ ๐ข๐ง/๐ญ๐ก๐ž-๐›๐ซ๐š๐ง๐œ๐ก (rebase your local with the remote)

Scenario B -> If you were just working on some changes but you did not commit them yet, you can simply

  1. ๐ ๐ข๐ญ ๐ฌ๐ญ๐š๐ฌ๐ก (To stash your local changes)
  2. follow the initial 2 steps to refresh the local branch
  3. ๐ ๐ข๐ญ ๐ฌ๐ญ๐š๐ฌ๐ก ๐ฉ๐จ๐ฉ (to get your local changes back)
  4. continue your work!

gitflow #trunkbaseddevelopment #softwareengineering #softwaredevelopment #git #github #versioncontrol

Top comments (0)