- while developing a project , there are a lot of commits that may be in the main branch or child branch. We don’t know when the branch with commit is developed .
- If we perform a merge, it adds commits in time linear (time sort) basic,
- so it will effect in testing, moving to production that particular commit ,
- so git rebase will merge child branch commits to main branch as latest commits.
** feature-1 is developed long back** after feature-1 , master got added another features** if we directly merge child(feature ) branch to master branch all commits are added in time linear manner** if we need feature-1 commits as latest commits, we need to use git rebase |
Steps to merge :
(i) Move to child branch or any branch :
git checkout feature-1 |
git rebase master |
→ command grab the master commit history , it will help full add child commits as latest , rebase won’t add commits to master branch , we need to run merge commands once again to add.
→ copies files from master and commits
(iii) Merge child with master :
git checkout master |
git merge feature-1 |
Observations :
We can see all the commits from master branch are moved to last and all commits from feature-1 came top/ as latest
Actual time linear commit history :