Saturday, December 20, 2014

Rebase in SourceTree

In the post Checkout (Create new Branch), we created a new branch and added a new file to the branch. Here we shall rebase this branch back into the main branch.

Unlike merge where the old branch is retained, in rebase the old branch is discarded and all the commits which were made to the branch are moved to the new branch to which the rebase is done. To rebase follow the below steps.

         1.            Open source Tree.
         2.            Checkout the main branch (master)
         3.            Make some changes to the files in the main branch (master), here I will add a new line to          the Git Commands.docx file.
         4.            Commit and push the changes.
         5.            Now Checkout the branch which is to be re-based. In our case it is the GitRebase branch
         6.            Now if we check the Git Command.docx file, you will not be able to see the new line which       we added and committed in the main branch (master).
         7.            Right click on the target branch (in our case we will rebase into the master branch)
         8.    Select the option “Rebase current changes onto


Command
$ git checkout GitRebase
$ git rebase master

         9.            Now open the same file Git Command.docx, notice that the new line which was added and committed in the main branch (master), is now reflected in this branch GitRebase. The rebase has caused to changes made to the file in the main branch to be merged with the file in this branch.
  10.   10.       The following diagram shows the state of the Git repository before and after rebase of the GitRebase branch into the main branch.



          11.            Notice that after rebase, the commit pointer of the GitRebase branch moves ahead of the master’s commit pointer, hence the changes done to the master branch are now reflected in the GitRebase branch after the rebase.
          12.            The actual representation of the branches in Source Tree is as follows.





Search Flipkart Products:
Flipkart.com

No comments: