How to Merge Branch to Master Branch using Git Command?

By Hardik Savani July 12, 2023 Category : Git

Do you have question how to merge branch to master github command line? than i am here for help to git merge branch to master. i will guide you step by step how to merge branch in git. i written all command for github merge branch into master branch.

Almost developer knows how to pull, how to commit, how to add and how push. no some developer that don't know how to create branch and merge branch with master.

Now in our field we are using git on our all laravel project as we can say. if you are working more than 3 developer than almost create developer wise own branch. developer work on his own branch. but than at last they merge in master branch. So how they are merge using command line i will show you step by step.

You have to simple follow this tutorial, i written step by step command for merge branch and how it works.

You can merge branch using following command:

git merge dev

git push origin master

Step by Step Explanation of Create and Merge Branch with Github

I already created my demo repository on my github account. You can also create your own. i will clone my repo by using following command:

git clone git@github.com:savanihd/Demo-Git.git

After clone i will go on that project.

cd Demo-Git/

Now i will check how much branch in my repo now. right now i have only master. you can see both screen.

git branch

* master

Now create master.html file in your master branch as like bellow:

master.html

<!DOCTYPE html>

<html>

<head>

<title>Master File</title>

</head>

<body>

</body>

</html>

Now you can push this file on your master branch using following command:

git add .

git commit -m "master file created"

git push origin master

Now i will create new branch for development using following command:

git branch dev

Check branch is created or not:

git branch

dev

* master

We created dev branch but still we are in master branch. So now we have to checkout in dev branch using following command:

git checkout dev

git branch

* dev

master

Now we are in dev branch. So we will create dev.html file on dev branch. so let's create with following code.

dev.html

<!DOCTYPE html>

<html>

<head>

<title>Dev File</title>

</head>

<body>

</body>

</html>

Now you can push this file on your dev branch using following command:

git add .

git commit -m "created dev file"

git push origin dev

Now we merge dev branch to master branch.

Let's run following command:

git checkout master

git merge dev

git push origin master

Now you can see on github repository and check it.

master branch merge with dev.

I hope it can help you...

Tags :
Shares