For Your Guidance – Technology

Rebase helps to change the history to branch source commit.

Scenario:

Let’s take branch “main” and the current sprint “Sprint1”. Planned to implement two features in the current sprint. Then, the developer will create a new branch from the main for each feature and make a commit. Later planned to postpone feature 2 to the next sprint.

#checkout main branch
git checkout main

#merge feature1 branch to main
git merge <feature1 branch>

Sprint 2 Starts: planned to include feature 2 and 3. Generally, we should create new branches from the main for each feature branch. But the feature 2 branch was already created in sprint 1 and also made some commits.

Possible Solutions:

Solution 1 :

Merge the feature 2 branch to the main in sprint 2.

Disadvantage: when we look into the commit history, it will show that the branch was created in sprint 1 and merged in sprint 2. Which is not expected as per the Sprint.

#checkout main branch
git checkout main

Sprint1:

#merge only fetaure1 branch to main in sprint1
git merge <feature1 branch>

Sprint2:

#merge feature2 branch changes in sprint2
git merge <feature2 branch>

 

Solution 2 :

Rebase the Feature 2 branch with the main branch current commit and then merge the feature 2 changes to the main.

Advantages: Commit history will show that the feature 2 branch was created in sprint2 only.

5/5
Tags: GIT / Merge / Rebase / SCM
Categories: GIT

Latest Posts