Saturday, December 20, 2014

Checkout (Create new Branch)

Checkout option in Git is used to switch between an existing branch to another, it can also be used to create a new branch and switch to the newly created branch. In the post Checkout in SourceTree (switch branches) we saw on how to use Checkout to switch to an existing branch, here we shall use the Checkout command to create a new branch and switch to the new branch.

To create a new branch and checkout to the new branch follow the below steps.
1.    Open source Tree.
2. In the repository which I use, we have 2 branches; we shall create a new branch using the Checkout command.


3.    Click on the Checkout option from the Toolbar.
4. Select the Tab “Checkout new branch”, select “master” as the source branch, give a name to the new branch “GitRebase” and click Ok.


5.    Notice that the new branch is created, and is marked as the current branch. Any changes committed at this point will be added to this branch.


6. Let us push the changes so that the new branch is added to the remote repository as well.


7.    Once pushed, you can login into your remote BitBucket repository and notice that the number of branches in the repository has increased by 1.
8.    Now let us add a new file to the branch, I am adding a new file called ‘Git Rebase.docx’
9. Stage the new file, commit and push the changes to the remote repository.


10. Now if we Checkout to the master branch,  you can see that the new file “GitRebase.docx” is not visible, also you can see that the new file is removed from the local working folder, since we added this file to the new Branch.  

Search Flipkart Products:
Flipkart.com

No comments: