Please do following set of commands in order to merge with the master, Assuming that you are in branch testBranch and you want to merge the changes with the master,

First checkout to master branch,

git checkout master

Now pull the latest changes in master,

git pull origin master

Merge with the testBranch

git merge testBranch

Push the changes to master

git push origin master

That's it, you are done.

Answer from Actung on Stack Overflow
🌐
Git
git-scm.com › book › en › v2 › Git-Branching-Basic-Branching-and-Merging
Git - Basic Branching and Merging
All you have to do is check out the branch you wish to merge into and then run the git merge command: $ git checkout master Switched to branch 'master' $ git merge iss53 Merge made by the 'recursive' strategy.
Discussions

How to Merge Master into a Feature Branch
I wouldn't. I usually just rebase feature branches onto master when they diverted too much. Unless this branch is collaborative, it should pose no issues. Just do so locally: [assuming you're on the feature branch and the remote is called origin] git fetch git rebase origin/master git push --force-with-lease More on reddit.com
🌐 r/git
14
2
March 13, 2024
How to merge branch to master?

Merge the development branch into master

  1. In the GitHub Desktop client, select the development branch. Make a change to a file, and then commit the changes.

2. Switch to the master branch.

3. Go to Branch > Merge into Current Branch.

4. In the merge window, select the development branch, and then click Merge into master.

Source - https://idratherbewriting.com/learnapidoc/pubapis_github_desktop_client.html

More on reddit.com
🌐 r/github
7
1
June 15, 2018
git - How to merge a branch to main branch in Github? - Stack Overflow
Or is it the default empty branch github provides? In the latter case, you don't need to merge, just rename one of your two branches to the other. ... The error you get on push is because you don't have a local main to push. You could overwrite remote main with git push -f origin master:main ... More on stackoverflow.com
🌐 stackoverflow.com
git - How to merge master branch into main - Stack Overflow
I have created a new remote repo "infrastructure" on GitHub. I have then created a local repo on my computer in the folder "infr" with git init · When I pushed my local repo with git push -u origin master the new branch "master" was created. I want to merge "master" branch into "main" branch now. More on stackoverflow.com
🌐 stackoverflow.com
Top answer
1 of 16
3750

How I would do this

git checkout master
git pull origin master
git merge test
git push origin master

If I have a local branch from a remote one, I don't feel comfortable with merging other branches than this one with the remote. Also I would not push my changes, until I'm happy with what I want to push and also I wouldn't push things at all, that are only for me and my local repository. In your description it seems, that test is only for you? So no reason to publish it.

git always tries to respect yours and others changes, and so will --rebase. I don't think I can explain it appropriately, so have a look at the Git book - Rebasing or git-ready: Intro into rebasing for a little description. It's a quite cool feature

2 of 16
558

This is a very practical question, but all the answers above are not practical.

Like

git checkout master
git pull origin master
git merge test
git push origin master

This approach has two issues:

  1. It's unsafe, because we don't know if there are any conflicts between test branch and master branch.

  2. It would "squeeze" all test commits into one merge commit on master; that is to say on master branch, we can't see the all change logs of test branch.

So, when we suspect there would some conflicts, we can have following git operations:

git checkout test
git pull 
git checkout master
git pull
git merge --no-ff --no-commit test

Test merge before commit, avoid a fast-forward commit by --no-ff,

If conflict is encountered, we can run git status to check details about the conflicts and try to solve

git status

Once we solve the conflicts, or if there is no conflict, we commit and push them

git commit -m 'merge test branch'
git push

But this way will lose the changes history logged in test branch, and it would make master branch to be hard for other developers to understand the history of the project.

So the best method is we have to use rebase instead of merge (suppose, when in this time, we have solved the branch conflicts).

Following is one simple sample, for advanced operations, please refer to http://git-scm.com/book/en/v2/Git-Branching-Rebasing

git checkout master
git pull
git checkout test
git pull
git rebase -i master
git checkout master
git merge test

Yep, when you have uppers done, all the Test branch's commits will be moved onto the head of Master branch. The major benefit of rebasing is that you get a linear and much cleaner project history.

The only thing you need to avoid is: never use rebase on public branch, like master branch.

Never do operations like the following:

git checkout master
git rebase -i test

Details for https://www.atlassian.com/git/tutorials/merging-vs-rebasing/the-golden-rule-of-rebasing

appendix:

  • if you are not sure about rebasing operations, please refer to: https://git-scm.com/book/en/v2/Git-Branching-Rebasing
🌐
Stack Abuse
stackabuse.com › git-merge-branch-into-master
Git: Merge Branch into Master
April 20, 2023 - $ git commit –m "Some commit message" $ git checkout master Switched to branch 'master' $ git merge new-branch · You always checkout the branch you're merging into, and merge a branch that already has changes. If you're newer to Git, though, it's worth taking a few minutes to understand ...
🌐
W3Schools
w3schools.com › git › git_branch_merge.asp
Git Branch Merge
To combine the changes from one branch into another, use git merge. Usually, you first switch to the branch you want to merge into (often main or master), then run the merge command with the branch name you want to combine in.
🌐
Delft Stack
delftstack.com › home › howto › git › best way to merge a git branch into master
How to Merge a Git Branch Into Master in Git | Delft Stack
February 2, 2024 - Now switch back to our repository example and merge the newly created feature-1 branch to master · First, check out the master branch. ... Now, pull the remote master changes to the local master. $ git pull origin master From github.com:repo/demorepo * branch master -> FETCH_HEAD Updating 17cc6b4..a802b6b Fast-forward file1.txt | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
🌐
Reddit
reddit.com › r/git › how to merge master into a feature branch
r/git on Reddit: How to Merge Master into a Feature Branch
March 13, 2024 -

I need advice on how to merge master into a feature branch.

I began working on a new feature last year, and then was pulled away to other things. Master had substantially changed, so I wanted to merge it back into the feature branch, because I can't keep working on the feature until those changes are incorporated into that branch.

I tried this in Github, but I could only merge into master, even when I selected merge into the feature branch. I finally just merged into master and manually updated the changes on the feature branch (which had been overwritten) through cut-and-paste on the feature branch. But this seems like a common task, and I don't want to have to do that again if I can help it.

Thanks in advance for any help; I did consult the Git book, but I couldn't find anything specific about this task.

Find elsewhere
🌐
Scribe
scribehow.com › viewer › How_to_Merge_Branch_to_Master_GitHub__HbCZCKOgQfeqxTh2K7Wb2A
How to Merge Branch to Master GitHub | Scribe
In this tutorial, we'll merge a feature branch into your master branch. You might want to do this after working on a new feature or bug in your secondary branch. When the time comes to merge back into the rest of your project, follow these steps.
🌐
Simple Dev
simpledev.io › home › merge branches – github desktop
Merge branches - GitHub Desktop - Simple Dev
May 16, 2022 - Select the branch you want to merge into master in the dialog box that appears, and then click the button that says Merge branch-name into master. Switching between branches – GitHub Desktop Help
🌐
GeeksforGeeks
geeksforgeeks.org › git › how-to-merge-a-git-branch-into-master
How to Merge a Git Branch into Master? - GeeksforGeeks
May 22, 2024 - Merge the changes from your feature branch into master. ... If Git reports conflicts, you'll need to resolve them manually.
🌐
Medium
medium.com › @scott.sourile › git-hub-merging-your-git-branches-from-the-website-directly-5bbc31b1d816
Git Hub: Merging your Git Branches from the website directly. | by Scott Sourile | Medium
October 30, 2023 - Once the pull request is created, you’ll see a “Merge pull request” button. If there are no conflicts, you can click on it to merge the test branch into main. If there are conflicts, GitHub will notify you, and you’ll need to resolve them before proceeding.
🌐
PhoenixNAP
phoenixnap.com › home › kb › devops and development › how to merge a git branch into master
How to Merge a Git Branch into Master | phoenixNAP KB
December 17, 2025 - The command switches to the master branch. After switching, use the git merge command to merge another branch into master.
🌐
Namehero
namehero.com › blog › how-to-merge-a-git-branch-to-master
How to Merge a Git Branch to Master
October 6, 2025 - This will get the most recent copy of the main branch. We’re ready to merge! Type the following command: ... As long as there are no conflicts, you can see that git merges the changes you made in the feature branch into main.
🌐
Barbagroup
barbagroup.github.io › essential_skills_RRC › git › branching
Branch and Merge - Essential skills for reproducible research computing
To do a merge (locally), git checkout the branch you want to merge INTO. Then type git merge <branch> where <branch> is the branch you want to merge FROM. We are on the master branch and want to merge in make_function so we do:
Top answer
1 of 15
1444

I generally like to merge master into the development first so that if there are any conflicts, I can resolve in the development branch itself and my master remains clean.

(on branch development)$ git merge master
(resolve any merge conflicts if there are any)
git checkout master
git merge development (there won't be any conflicts now)

There isn't much of a difference in the two approaches, but I have noticed sometimes that I don't want to merge the branch into master yet, after merging them, or that there is still more work to be done before these can be merged, so I tend to leave master untouched until final stuff.

EDIT: From comments

If you want to keep track of who did the merge and when, you can use --no-ff flag while merging to do so. This is generally useful only when merging development into the master (last step), because you might need to merge master into development (first step) multiple times in your workflow, and creating a commit node for these might not be very useful.

git merge --no-ff development
2 of 15
135

Personally, my approach is similar to yours, with a few more branches and some squashing of commits when they go back to master.

One of my co-workers doesn't like having to switch branches so much and stays on the development branch with something similar to the following all executed from the development branch.

git fetch origin master    
git merge master    
git push origin development:master

The first line makes sure he has any upstream commits that have been made to master since the last time updated his local repository.

The second pulls those changes (if any) from master into development

The third pushes the development branch (now fully merged with master) up to origin/master.

I may have his basic workflow a little wrong, but that is the main gist of it.

🌐
GitHub
docs.github.com › en › desktop › contributing-and-collaborating-using-github-desktop › keeping-your-local-repository-in-sync-with-github › syncing-your-branch
Syncing your branch in GitHub Desktop - GitHub Docs
September 5, 2022 - To apply changes to your branch from another branch in the same repository, you can merge the other branch into your branch on GitHub Desktop. To request that changes from your branch are merged into another branch, in the same repository or in another repository in the network, you can create a pull request on GitHub Desktop.