How to merge two branches in GIT?

Merge two branches in GIT
Some it makes confuse us that how can i merge the branches in GIT
when we have two branches in GIT

Let say there are two branches on GIT
one is master and second is develop

And you are changing the code develop branch finish you code
Now you want to merge the code with master

So first of all you need to go to master branch because this is the branch which you want to merge with new code

So first command you will run
git checkout master

Now you can see that you are in master branch
Now run second command to merge both of branch
git merge develop

This command will merge both of branches in one now master has same code as develop
Now you need to run commit command with message
git commit -m "merge two branches in git"

Now push the changes on your master branch to update the code on server
git push origin master

Its done and it simple to merge two branches.

Note: Keep in mind that master branch does not have any other update direct committed on master branch from other user.
I mean to say all file on master branch should be same as develop branch only develop branch can have changed file on your local server.

If master branch has changes and those changes are not on develop server then you need to run this command first
git pull origin master

Then you can follow the process from start

Keep in Mind: Always git pull from server before push the commit
Like: from develop
git pull origin develop

or for master
git pull origin master

Comments