Help
cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Ground Controller Lvl 2
Message 1 of 2

Branch

Solved! Go to Solution.

Hi everyone,

I have some question about the branch

 

1. I searched about the Branch in Google. There are so many explained about this function, but I don't know what's the relation with Merge. Every explains were written with merge.

2. How can i know at git that the branch has already been merged as a master?

3. What is the main reason to use brunch in git?

 
Thank you
 
1 Reply
Solution
Commander Lvl 2
Message 2 of 2

Re: Branch

Hi @joe97228,

 

Welcome to the Github Community Forum!

 


@KyungsooJ wrote:

1. I searched about the Branch in Google. There are so many explained about this function, but I don't know what's the relation with Merge. Every explains were written with merge.


The branch without merge is like having an hair comb with no hair. Yes, you can use it but you never appreciate it. With example maybe you can understand better. Think about a git repository with some commits:

 

              master ->  A---B---C---D

 

The A, B, C and D are commits that perfectly solve a single problem and you can present as a finished project as is. Now you want to try to create a new feature without touch the main project. Without git you can copy and paste the project in another directory and start to make some changes, but we are brave enough to try using git(?). With git you need to create a new history path with branches, in our example we are going to create a branch called new.feature:

 

                            new.feature ->  E---F---G

                                  git branch  /

              master ->  A---B---C---D

 

The new commits E, F and G solved the new feature we want to create and we are ready to present this new version of the project. But how can we manage to substitute the last commit D of the master branch? With the merge command:

 

                            new.feature ->  E---F---G

                                  git branch  /             \   git merge

              master ->  A---B---C---D---

 

The new history is this one with the E, F and G commits head after A, B, C and D commits:

 

              master ->  A---B---C---D---E---F---G

 

Hope you understand.

PS: Ask if you want step to step git command tutorial for this example.

 


@KyungsooJ wrote:

2. How can i know at git that the branch has already been merged as a master?


If you are using the git in console/terminal you can simply use the log command of the branch and compare with the log of the branch master. If commits of the branch are the same in the master branch so that branch is already merge. Alternatively you can try to merge that branch into master without create commit using the command merge with argument --squash and watch if there are some changes to stage.

If the question is: How can i know at GITHUB that the branch has already been merged as master? The answer is you can see the branch status in the overview into the web ui at https://github.com/<user_name>/<repository_name>/branches.

 


@KyungsooJ wrote:

3. What is the main reason to use brunch in git?

 

Because the branch is the Thor's hammer of git. To be more precise branching is used to work in team, solve issues without touch the master version, try to add new features and discard them if are not required and so on. There is nothing to stop you from using only the master branch, even Thor can beat small enemies without the hammer.

 

Ask if you have more questions...

 

-Gabriele-

 

Mark helpfull posts with Accept as Solution to help other users locate important info. Don't forget to give Kudos for great contents!