ItSolutionStuff.com

How to Merge Your Branch to main Branch in Github?

By Hardik Savani • November 6, 2024
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.

Output:

I hope it can help you...

Tags: Git
Hardik Savani

Hardik Savani

I'm a full-stack developer, entrepreneur, and founder of ItSolutionStuff.com. Passionate about PHP, Laravel, JavaScript, and helping developers grow.

📺 Subscribe on YouTube

We Are Recommending You

How to Remove File from Git Commit Before Push?

Read Now →

How to Delete a Branch form GitHub Repository?

Read Now →

How to Rename Branch Name in Git Command?

Read Now →

How to Switch Branch using Git Command?

Read Now →

How to Create a New Branch on GitHub?

Read Now →

How to Ignore Wildcard Files Name in Git using Gitignore?

Read Now →

Laravel 9 Socialite Login with Github Account Example

Read Now →

Git Command to Ignore File Permission Changes

Read Now →

How to Add Git Add Remote Origin on Bitbucket Repository?

Read Now →

Git - How to Find a Deleted File in Commit History?

Read Now →

How to Configure Git Username and Email?

Read Now →

How to Git Force Pull from Remote Branch?

Read Now →

Git Remove Last Commit from Local Example

Read Now →

How to remove current changes from local system in Git ?

Read Now →