Git and Github Tutorial - Merging Branches - Part 10

Hi, Today in iThePro we will learn how to use Git and how to use with Github to build software and develop it. In this part we will see Merging Branches

Merging code:
how to bring changes from branch back to the master branch, we do this with command :
git merge <branch-name>
Using a fast-forward merge vs. true merge:

Fast-Forward Merge:
This type of merge happen when you merge a branch2 to a branch1, and you stop committing in branch1 when you start with branch2.
is just copy branch2 and paste in the tip of branch1 .
git merge --no-ff <branch-name>
This will merge the <branch-name> and made it with new commit, so there is no fast-forward merge.
git merge --ff-only <branch-name>
This will tell git to do a fast-forward only if he can, if not so abort.

True Merge:
This type of merge will merge branch and made out a new commit for that.

Merging Conflicts:
Git will got conflict when you trying to merge branch with another and both off them have different same line code.

Resolving Merge Conflicts:
We have 3 Solution to resolve merge conflicts.

Abort Merge:
git merge --abort
Use a merge tool:
git mergetool --tool= //search for it
 Resolve the conflicts manually:

2)You notice that you are in the middle of Merging
3)Modified the file
4)git add
5)git commit

Exploring Strategies to reduce merge conflicts:
-keep lines short

-keep commits small and focused:
               commits every time you change something.

-beware from edits to whitespace:
               try to do not use (space, tabs, line returns).

-merge often:
               keep always merge you're branch to reduce conflicts.

-track changes to master:
               keep always as much as you can up to date with the master branch.

See the Git and Github Tutorials.




Oussama Amri 21 years, security professional from Tunisia. Lover of computer science especially programming and secuirty. Follow me On :

Popular Posts Powered by Blogger.