How To Rebase Git Branch

Here is the scenario where we need rebase.

main is the base branch and 2 sub branches add and subtract were created from main. Developer A is working on add and developer B is working on subtract. 

Developer A pushed his changes and merged the code to main. But B is still working on his changes. After some time, now B is pushed his changes and tries to merge the code into main branch. Here is the place where B will face “This branch has conflicts that must be resolved” issue. 

Now, how developer B should avoid this issue ? 

Here is the solution! After committing his changes and before he pushes the code, he must do these below steps,

  1. Checkout the main branch
    • git checkout main
  2. Pull the latest changes
    • git pull –rebase 
  3. Checkout the sub branch
    • git checkout subtract
  4. Rebase this branch with main branch
    • git rebase main
  5. Pull the rebased changes
    • git pull –rebase
  6. Push the changes now
    • git push

Let’s run the git log command to see the history.

The log tells that the add branch changes are merged to subtract branch.

Now, the developer B can proceed to merge the branch.

I hope this post helped you to resolve the merge conflicts.

at java.base/java.util.ArrayList$Itr.checkForComodification at java.base/java.util.ArrayList$Itr.checkForComodification(ArrayList.java:1013) create simple spring boot application default spring security dynamic programming in java employee filter by department id equals() Exception in thread "main" java.util.ConcurrentModificationException flutter exception garbage collection garbage collection models garbage collector Git commit Git conflicts Git merge hashCode() hashCode() and equals() in java how heap works how to create simple spring boot application I have of a list of employees. I want to retrieve only the employees from dept 1. Write a program in java 8. importance of hashCode() and equals() java 5+ years interview questions java 7+ years interview questions Java8 filter java 8+ years interview questions java backend developer interview quesions java filter by departmentid java fullstack developer interview questions java garbage collector java heap java interview questions java junior developer interview questions java memory management java nursery java regular expressions java senior developer interview questions keep area layers in java memory regular expressions secure spring boot application simple spring boot spring boot spring security This branch has conflicts that must be resolved Why do I need to override the equals and hashCode methods in Java?