GIT Branches

From SIMA wiki
Jump to: navigation, search

Branching mean you diverge from the main development line into a parallel development line.

We distinguish between local and remote branches.

Local branches

The local branches are the branches you work with. It isn’t possible to commit changes to the remote brunch. So GIT creates a local brunch to store these changes.

Remote Branches

The remote branches are the state of the remote repository of your last fetch. So they are only a local representation of the branch in the remote repository. They have the form

remote/[remote name]/[branch name ]

e.g. remote/origin/master

  • origin … the name of the remote repository (by default origin)
  • master… the name of the selected branch

It is possible to get different branches from different remote repositories.


If you want to combine two branches you have two possibilities:

Merging

Git merge.PNG

If you can see in the picture Version 7 is based on Version 5 (function xy brunch) and on Version 6 (master brunch). If in two separate branches the same part of the same file is changed there are conflicts when merging the branches. GIT doesn’t create a merge commit (like V7) until you have manually solved the merge conflict. It is possible to solve the conflict manually by changing the file, or to use a merge tool. These Tools jump from conflict to conflict and display the differences in a graphical way.

Rebase

Another way to bring the parallel brunch back to the mast branch is to rebase the parallel branch.

Git rebase.PNG

In this example the new base for the Version 4 is set to Version 6. The changes done in V4 and V6 are applied to V6.The last step is to da a fast forward merge to let the master point at V5’. The result of the rebase is the same as the result of the merge, but you get a linear history. It seems that the changes would have been taken sequentially.