149

I have two branches in git: master and custom_branch.

Somebody added some code to master that I need to use in my custom_branch. I tried this:

git branch custom_branch
git merge master

But when I do that, it says:

Already up-to-date.

But, when I compare master and custom_branch, the changes are still not there. What am I missing?

P.S. I don't want to rebase since other people also use this branch.

Darth.Vader
  • 5,079
  • 7
  • 50
  • 90
  • 5
    Because with the command that you provided `git branch custom_branch` you don't change to `custom_branch` just staying on `master`. Execute `git checkout custom_branch` and if the master have some changes in master after you created the `custom_branch` then if you want to merge the changes to your `custom_branch` execute `git merge master`. – IamK Dec 08 '16 at 18:04
  • 2
    I already suggested this in my answer, but he seems to have an issue with git not recognizing changes. – tehp Dec 08 '16 at 18:07
  • having the same issue. Have rebased and tried merging multiple times. git says up to date but the changes are not merging to my custom_branch. I can see the changes when i checkout the master branch. – Harshit Nagar Nov 12 '20 at 08:17

6 Answers6

188

git checkout custom_branch && git rebase master

This will update custom_branch with changes from master branch.

Don't forget to make sure master is up to date first. git pull


This is also possible with git checkout custom_branch && git merge master


For an explanation on why the first one is (probably) what you should be using: When do you use git rebase instead of git merge?
Community
  • 1
  • 1
tehp
  • 5,018
  • 1
  • 24
  • 31
  • 5
    thanks, but I don't want to rebase since others are also using this branch. Also, running the second command says everything is already up to date. – Darth.Vader Dec 08 '16 at 17:52
  • 5
    @Darth.Vader have you ran `git pull` before attempting to merge? – tehp Dec 08 '16 at 17:59
  • After doing this I get this message "Updates were rejected because the tip of your current branch is behind hint: its remote counterpart." What should I do? – Ollie Williams Jul 04 '22 at 16:15
64

git merge master will update your current branch with the changes from your local master branch, the state of which will be that of when you last pulled while on that branch.

I think this is what you are looking for: git merge origin master

Tilman
  • 734
  • 5
  • 10
23

Answering my own question but to pull changes from upstream's master into my custom branch I did this:

git pull [URL TO UPSTREAM'S REPO] master
Darth.Vader
  • 5,079
  • 7
  • 50
  • 90
7

Just do:

git fetch origin master

And then do:

git merge master
Pritam Banerjee
  • 17,953
  • 10
  • 93
  • 108
3

You probably still have to pull the changes to your local master branch. Before your commands, use git checkout master and then git pull

0

Be sure that you're on the branch you want to merge into. Command for merging master into the

git merge master && git commit -m "merging master" && git push

Lily
  • 1
  • 3