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:
- ๐ ๐ข๐ญ ๐๐๐ญ๐๐ก ๐จ๐ซ๐ข๐ ๐ข๐ง ๐ญ๐ก๐-๐๐ซ๐๐ง๐๐ก (fetch branch from origin)
- ๐ ๐ข๐ญ ๐ซ๐๐ฌ๐๐ญ --๐ก๐๐ซ๐ ๐จ๐ซ๐ข๐ ๐ข๐ง/๐ญ๐ก๐-๐๐ซ๐๐ง๐๐ก (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:
- ๐ ๐ข๐ญ ๐๐๐ญ๐๐ก ๐จ๐ซ๐ข๐ ๐ข๐ง ๐ญ๐ก๐-๐๐ซ๐๐ง๐๐ก (fetch remote branch)
- ๐ ๐ข๐ญ ๐ซ๐๐๐๐ฌ๐ ๐จ๐ซ๐ข๐ ๐ข๐ง/๐ญ๐ก๐-๐๐ซ๐๐ง๐๐ก (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
- ๐ ๐ข๐ญ ๐ฌ๐ญ๐๐ฌ๐ก (To stash your local changes)
- follow the initial 2 steps to refresh the local branch
- ๐ ๐ข๐ญ ๐ฌ๐ญ๐๐ฌ๐ก ๐ฉ๐จ๐ฉ (to get your local changes back)
- continue your work!
Top comments (0)