45

I do have a local branch with some changes, and I want to merge it to remote master. When I run: git merge master I get:

Already up-to-date

but I still can see that the master doesn't contain the new changes.

I checked the following issue Git merge reports “Already up-to-date” though there is a difference Ask, but it seems in one hand to be outdated, and on the other hand, none of the hints there were helpful.

Any idea or hint?

k.vincent
  • 3,743
  • 8
  • 37
  • 74
  • `git pull origin master` on your branch – Davin Tryon Nov 02 '17 at 10:21
  • 2
    `git merge master` merges _from_ master _to_ the currently checked out branch. – tkausl Nov 02 '17 at 10:22
  • Yes, I did all these commands. – k.vincent Nov 02 '17 at 10:24
  • Do you want to reflect your branch changes on master or vice versa? If you want to have the changes on master you should rather checkout master and run a `git merge `. – ckruczek Nov 02 '17 at 10:28
  • Does this answer your question? [What is the best (and safest) way to merge a Git branch into master?](https://stackoverflow.com/questions/5601931/what-is-the-best-and-safest-way-to-merge-a-git-branch-into-master) – Abu Shoeb May 05 '21 at 20:52

4 Answers4

86

If you want to merge your branch to master on remote, follow the below steps:

  1. push your branch say 'br-1' to remote using git push origin br-1.
  2. switch to master branch on your local repository using git checkout master.
  3. update local master with remote master using git pull origin master.
  4. merge br-1 into local master using git merge br-1. This may give you conflicts which need to be resolved and changes committed before moving further.
  5. Once merge of br-1 to master on local is committed, push local master to remote master using git push origin master.
fedorqui
  • 275,237
  • 103
  • 548
  • 598
divsingh
  • 1,172
  • 8
  • 15
  • 3
    TL;DR `git checkout master; git merge yourbranch` (the other steps are unrelated to branch merging, and not everyone may have a remote set (I often work in git locally just for a personal project)) – Luc Apr 29 '22 at 09:02
  • oops... by using git checkout master, all the changes are gone, so follow this, when you checkout to master branch, then pull code from staging branch and push to master branch. – Imran_Developer Jun 29 '22 at 18:59
  • Why would you push branch to remote? I think you should remove branch after merging to not get confused . – Grzegorz Krug Oct 09 '22 at 15:11
13

To merge branch with master,there are two ways you can proceed

  • By Git commands
  • By Github Dashboard

Git Commands

Here also you can go with two different commands,first is

  • checkout to your master branch using git checkout master
  • pull your latest code from the branch you want to merge,use git pull --rebase origin branch_name. It may give you some conflicts which you can resolve by using git status,after resolving you can check if any conflict is more there or not by using git rebase --continue.

Second way

  • To master you can cherrypick the commits from the branch you want to merge git cherry-pick <commit id>.If you are getting conflict use git cherry-pick --continue.

Actually this is the more suggested way you can proceed.

Merge branch using GitHub Dashboard

This is most easiest way to merge. Create new pull request, select the branch you want to merge and resolve the conflicts.

alper
  • 2,919
  • 9
  • 53
  • 102
Navneet
  • 410
  • 3
  • 10
0

Merging into master Or another branch:

git merge master / or yourBranchName

After merging it, check if there is a conflict or not.
If there is NO CONFLICT then:

git push

If there is a conflict then fix your file(s), then:

git add yourFile(s)
git commit -m 'merging my branch'
git push
Bayram Binbir
  • 1,531
  • 11
  • 11
0

I tried this solution and it works :

If you want to merge your branch to master on remote, follow the below steps:

push your branch say 'br-1' to remote using git push origin br-1. switch to master branch on your local repository using git checkout master. update local master with remote master using git pull origin master. merge br-1 into local master using git merge br-1. This may give you conflicts which need to be resolved and changes committed before moving further. Once merge of br-1 to master on local is committed, push local master to remote master using git push origin master.