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

Answer from KingCrunch on Stack Overflow
🌐
Git
git-scm.com › docs › git-merge
Git - git-merge Documentation
Produce the working tree and index state as if a real merge happened (except for the merge information), but do not actually make a commit, move the HEAD, or record $GIT_DIR/MERGE_HEAD (to cause the next git commit command to create a merge commit).
🌐
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.
Discussions

How do I safely merge a Git branch into master? - Stack Overflow
A) Create a PR (e.g. on GitHub) and merge it there via the UI · B) Go back on the command line and merge the branch into master More on stackoverflow.com
🌐 stackoverflow.com
git merge through terminal - Stack Overflow
If you have set vim as your editor, ... after git merge --no-ff. After you entered your commit message, you need to save message and exit vim. ... IIRC correctly, you answered this well after me. This is almost exactly what I said. 2016-02-28T20:41:24.72Z+00:00 ... @intboolstring I admit I get hints from your answer, thank you. but the command you provided ... More on stackoverflow.com
🌐 stackoverflow.com
What are the exact git commands Github uses when merging a PR?
No your 3rd point is incorrect (the other 2 are ok). It’s merge, OR merge -squash, OR rebase your changes onto the destination. Once your commits have been moved to Main via rebasing there is no Merge following it (it wouldn’t do anything if there was - it would be empty, as your two branches would be exactly the same at that point. This is merge -ff More on reddit.com
🌐 r/git
15
7
February 3, 2023
Git Merge – The Definitive Guide
I always recommend Pro Git . Even if you think you know git. And then read CH 10 git internals. And if you’re really ambitious, read Building Git where you implement your own fully fledged git. Brilliant book! More on reddit.com
🌐 r/programming
164
907
May 26, 2023
🌐
Atlassian
atlassian.com › git › tutorials › using branches › git merge
Git Merge | Atlassian Git Tutorial
In the event that you require a merge commit during a fast forward merge for record keeping purposes you can execute git merge with the --no-ff option. ... This command merges the specified branch into the current branch, but always generates ...
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
🌐
Git
git-scm.com › book › en › v2 › Git-Branching-Basic-Branching-and-Merging
Git - Basic Branching and Merging
Suppose you’ve decided that your issue #53 work is complete and ready to be merged into your master branch. In order to do that, you’ll merge your iss53 branch into master, much like you merged your hotfix branch earlier. All you have to do is check out the branch you wish to merge into and then run the git merge command:
🌐
GeeksforGeeks
geeksforgeeks.org › git › git-merge
Git Merge - GeeksforGeeks
May 9, 2026 - Performs fast-forward or automatic merges unless conflicts occur. Commonly used to integrate feature branches into the main branch. Using the diagrams below, we will see how git merge works what the repository looks like before the merge and ...
Find elsewhere
🌐
LaunchCode
education.launchcode.org › intro-to-professional-web-dev › chapters › git › merge.html
22.5. Merging in Git
With merging in Git, the command to perform a dry-run and make sure there aren't any conflicts is git merge --no-commit --no-ff <branch>. The --no-commit and --no-ff syntax tells Git to run the merge without committing the result to the repository.
🌐
CraftQuest
craftquest.io › homepage › git version control › 6. git workflow tools › git merge
Git Merge - Git Version Control | CraftQuest
August 29, 2022 - Git vs. SVN Commands ... Git-merge allows you to join togeth­er two dif­fer­ent his­to­ries into one.
🌐
Git
git-scm.com › docs › git-merge-file
Git - git-merge-file Documentation
... This option may be given up to three times, and specifies labels to be used in place of the corresponding file names in conflict reports. That is, git merge-file -L x -L y -L z a b c generates output that looks like it came from files x, y and z instead of from files a, b and c.
🌐
Reddit
reddit.com › r/git › what are the exact git commands github uses when merging a pr?
r/git on Reddit: What are the exact git commands Github uses when merging a PR?
February 3, 2023 -

So there's 3 options when merging a PR in Github:

  1. Create a merge commit

  2. Squash and merge

  3. Rebase and merge

Just looking at https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/incorporating-changes-from-a-pull-request/about-pull-request-merges, I still had a few questions on exactly what git commands Github is using when merging a PR.

Create a merge commit

Is this just git merge --no-ff?

It looks like you'll always have a merge commit, regardless whether the PR branch had diverged or not.

Squash and merge

Is this squashing commits (git rebase -i) and then git merge or git cherry-pick?

It looks like for both diverged/non-diverged branches, this always results in your squashed commit going in linearly onto the main branch.

Rebase and merge

This one I'm more confident about. This looks like a git rebase and git merge.

It rebases your feature branch onto main, then merges all the commits in, putting all feature commits into the main branch. This is opposed to the other options which either give you a merge commit or one squashed commit.

🌐
Uidaholib
uidaholib.github.io › digital-collections-docs › content › maintainers › merging.html
Merging Main into Branch | Digital Collections Docs
If there are no conflicts, merge message will pop up, type Ctrl+X to save default message. If there are conflict, merge will stop and you will have to resolve the conflicts first (edit them in VS Code), then complete the merge commit. ... GitHub Desktop will list the conflicts you need to resolve before the merge can be committed.
🌐
Git Tower
git-tower.com › learn › git faq › how to merge branches in git with git merge
How to Merge Branches in Git with git merge | Learn Version Control with Git
5 days ago - No need to remember all those commands and parameters: get our popular "Git Cheat Sheet" - for free! ... Our goal is to integrate the changes from "contact-form" back into "master". Before merging your code into one of your project's long-running branches (like a "development" or "master" branch), make sure that your local repository is up to date.
🌐
Medium
medium.com › david-fellows › git-branch-and-merge-made-easy-ec6918469837
Git branch and merge. Step by step instructions and reference… | by David Fellows | David Fellows | Medium
October 3, 2019 - Commands here vary but hopefully you will be able to exit by hitting the escape keeping, typing q!, and then enter. Step 7— Git checkout master #switch to master branch ... Although git status shows there is nothing to commit, the master branch is not update to date with your examplebranch ... Merging your branch into the master will overwrite your master branch with the changes you made in your new branch.
🌐
Medium
medium.com › @nathanmkaya › git-command-line-merging-b30b2663cca5
GIT: command line merging. I have been using git and code… | by Nathan Mkaya | Medium
June 22, 2017 - To begin with git mergetool --tool-help list all possible tools that can be installed and that can work with git.
🌐
GitLab
docs.gitlab.com › topics › git › merge
Merge your branch into the main branch | GitLab Docs
... remote: To create a merge request for my-new-branch, visit: remote: https://gitlab.example.com/my-group/my-project/merge_requests/new?merge_request[source_branch]=my-new-branch
🌐
Guvi
ftp.guvi.in › hub › git-tutorial › merging-in-git
What is Merging in Git?
This guide covers Git fundamentals, ... merging, and working with remote repositories on GitHub. It helps learners manage code changes confidently and collaborate effectively in real projects. ... This handbook introduces version control using Git and GitHub in a step-by-step manner. You’ll start with basic Git commands, learn how ...
🌐
Reddit
reddit.com › r/programming › git merge – the definitive guide
r/programming on Reddit: Git Merge – The Definitive Guide
May 26, 2023 - You totally can, under normal circumstances you'll never need to know its internals or use any of the more esoteric commands people like to complain about. ... That alt text is far too prescient. ... My favourite merge conflict was a blank line. Gotta love git.
🌐
Scaler
scaler.com › home › topics › git › git merge
Git Merge - Scaler Topics
May 4, 2023 - The command can create, rename, list, and delete branches. Git merge is one of the most widely used commands that is used to merge multiple commits (that may be stored in several branches) into a single branch.
🌐
Linux Hint
linuxhint.com › how-to-git-merge
How to Git Merge | Beginner Git Tutorial – Linux Hint
To merge Git branches, firstly, navigate to the repository, and create a file. Next, track a new file in the repository and update the repository by committing changes. Then, execute the “$ git merge <branch>” command to merge the Git local branches.