My scrapbook about anything which I learned or want to remember, Sometime about tech tips, thoughts and rambling. If you find anything useful don't forget to give thumbs-up :)

Breaking

Wednesday, November 21, 2018

Let's Learn - Git Branching #1


Git branching feature is the most notable feature provided by Git for parallel development without impacting other developers. Using git branches, Developers can work on different module parallel with same base code and merge them later into one to build the complete picture.

We will start with the simple branching scenarios, where 2 branch has been initiated with same base code and merge them into one after few modifications.

a. List Git Branch:
==

b. Create Git Branch:
==

By above command, you can create a branch which has the same base code as master and when you list the branch, now you can see 2 names - atul (branch we created) and master (original). Asterisk * sign will tell us which repo is currently active.


c. Switch to Git Branch (checkout branch): 
===
To checkout branch is very easy and can be done by above command quickly. Just remember that whatever changes you have done in this branch will be local (remain) in this branch only.

d. Let's make some changes in the branch:
To make some changes, what I have done is created a new file name "atul.txt" and committed to this branch named "atul". You can found all the commands as below -
= =

now, we have made the changes, let's check the git log for this branch -


Here we have to understand one important branching concept, as you can see there are 2 branches (master and atul) pointer.

origin/master, master - this pointer will tell this branch "atul" has been branched from "master" from this commit de70bc2450802c80dc5520afa20b53de30488e5a

HEAD -> atul, origin/atul - this pointer will tell you that HEAD is pointing to "atul" branch means you are inside "atul" branch and commit 0ba89ab2d62a74c48951ba20b2c0f369c9a675a3 has been done

Let's quickly move to master branch and check whether these changes are there or not ??

e. Moving back to master:
Moving back process is the same as moving into the branch and check the git log in "master" branch


Here you can see that changes which we have committed inside "atul" branch hasn't been reflected in "master" branch.

This is how Git support Parallel Development with branching where the developer can create their own branch and develop the different features parallel.

f. What's the differences: 
We have created 2 branches named: "master" & "atul" and made some additional changes inside "atul" branch and commit to it. We can check the difference between these 2 branches by executing below command :
==

We will discuss about how to interpret this diff report in the next post, till then.....Happy Learning........





Like the below page to get the update  
Facebook Page      Facebook Group      Twitter Feed      Google+ Feed      Telegram Group     


Disclaimer

The postings on this site are my own and don't necessarily represent IBM's or other companies positions, strategies or opinions. All content provided on this blog is for informational purposes and knowledge sharing only.
The owner of this blog makes no representations as to the accuracy or completeness of any information on this site or found by following any link on this site. The owner will not be liable for any errors or omissions in this information nor for the availability of this information. The owner will not be liable for any losses, injuries, or damages from the display or use of his information.