415

I have a git repository with 2 branches: master and test.

There are differences between master and test branches.

Both branches have all changes committed.

If I do:

git checkout master
git diff test

A screen full of changes appears showing the differences. I want to merge the changes in the test branch and so do:

git merge test

But get the message "Already up-to-date"

However, examining files under each different branch clearly shows differences.

What's the problem here and how do I resolve it?

Narek
  • 38,779
  • 79
  • 233
  • 389
Charles Darke
  • 4,461
  • 3
  • 18
  • 9
  • Do you have un-commited modified code? – ozma Jan 30 '17 at 05:57
  • Does this answer your question? [Why does Git say my master branch is "already up to date" even though it is not?](https://stackoverflow.com/questions/15376241/why-does-git-say-my-master-branch-is-already-up-to-date-even-though-it-is-not) – Michael Freidgeim Apr 15 '20 at 12:19

23 Answers23

220

The message “Already up-to-date” means that all the changes from the branch you’re trying to merge have already been merged to the branch you’re currently on. More specifically it means that the branch you’re trying to merge is a parent of your current branch. Congratulations, that’s the easiest merge you’ll ever do. :)

Use gitk to take a look at your repository. The label for the “test” branch should be somewhere below your “master” branch label.

Your branch is up-to-date with respect to its parent. According to merge there are no new changes in the parent since the last merge. That does not mean the branches are the same, because you can have plenty of changes in your working branch and it sounds like you do.

Edit 10/12/2019:

Per Charles Drake in the comment to this answer, one solution to remediate the problem is:

git checkout master
git reset --hard test

This brings it back to the 'test' level.

Then do:

git push --force origin master

in order to force changes back to the central repo.

jkeys
  • 3,803
  • 11
  • 39
  • 63
Bombe
  • 81,643
  • 20
  • 123
  • 127
  • 2
    Holy cr*p! You're right! I think what happened was that another branch (unstable development) was incorrectly merged with master and the test branch was a sub-set of unstable. The merge I was trying to make was to bring master back to the 'test' level. – Charles Darke Mar 11 '09 at 14:29
  • 2
    Right. That operation wouldn’t make any sense so Git refuses to do anything. :) – Bombe Mar 11 '09 at 14:50
  • 27
    What I've done now is: git checkout master; git reset --hard test; This brings it back to the 'test' level. I then did a "git push --force origin master" to force changes back to the central repo. – Charles Darke Mar 11 '09 at 14:52
  • 30
    Would have been nice if git had a warning to say "trying to merge with parent". – Charles Darke Mar 11 '09 at 14:54
  • 2
    Pushing a branch that is not a descendant of the branch already existing on the remote side is considered a bad thing: See the discussions on the man pages for git-push and git-pull. – Bombe Mar 11 '09 at 15:35
  • Yeah. Unpicking the whole thing would have taken too long, so I just backed up the repo, did the force push and checked result was what I wanted. – Charles Darke Mar 12 '09 at 13:17
  • 1
    What if you want to merge from Master to a child branch because you want to selectively revert some portions of some commits through merge conflict resolution rather than rolling back whole commits? Is that feasible or possible? – ThePartyTurtle Nov 10 '17 at 22:07
  • My case is the opposite, updating my feature with new changes in r25 branch, both these branch were created from develop. I did git checkout feature, git merge r25 and some files were merged and comitted and pushed. However, the merge did not merger all differences i.e. changes in r25. Now, when i try git merge again I get Already-upto date. – Prakash Mar 08 '18 at 02:29
  • @CharlesDarke your suggestion helped me out so I merged it into the answer. Thanks for the help, over ten years later. – jkeys Oct 13 '19 at 12:40
  • How is this situation most often encountered? I don't understand how I got in this position. – Noel Evans Jan 10 '20 at 16:32
  • In my case, it looks like my "test" wasn't the parent of my "master", but the parent of another branch that I had already merged. – Vince Apr 30 '20 at 01:16
185

This often happens to me when I know there are changes on the remote master, so I try to merge them using git merge master. However, this doesn't merge with the remote master, but with your local master.

So before doing the merge, checkout master, and then git pull there. Then you will be able to merge the new changes into your branch.

Kalle Richter
  • 8,008
  • 26
  • 77
  • 177
ACarter
  • 5,688
  • 9
  • 39
  • 56
  • 9
    Is there a way the switching of branches can be avoided, something like do a pull of the branch to be merged while still at the branch to be merged into, and then merge? – Japheth Ongeri - inkalimeva Oct 18 '16 at 13:59
  • 4
    Ahh, nice one. I thought `git fetch` would update the master branch even if I am currently on a different one. Turns out it does not. Thanks! I am pretty sure there is an option for `fetch` that lets you specify which branch to get. – Raik Jul 30 '17 at 15:53
  • 2
    @Raik You can do `git fetch --all`, but this only fetches the branches, it doesn't pull them. – Ingo Bürk Nov 02 '17 at 11:16
  • 9
    @JaphethOngeri-inkalimeva You can just do `git fetch --all && git merge origin/master`. No need to update your local `master` to merge remote changes. – Ingo Bürk Nov 02 '17 at 11:17
  • 1
    @IngoBürk I had 2 branches, updated 1 with `git merge master` and 1 with `git merge origin/master`. I also had checked out `master` and `git pull` prior to updating 2 branches. even though they shared the same content, creating a PR between the 2 branches showed some diff files. I fixed by `git pull` the target branch into feature branch, which showed: `Already up to date! Merge made by the 'recursive' strategy.` this resulted in merge commit with no changes, but removed the unexpected diff files from PR. any idea why there is a diff between merging "equivalent" local and remote branches? – wrapperapps May 20 '19 at 17:50
  • you can also do a `git rebase origin/master`. This will rebase against your remote, instead of your local master which may be behind. – Govind Rai Aug 06 '19 at 00:19
  • In my case, I hadn't realised, but the `git pull` had failed/ been aborted due to `error: The following untracked working tree files would be overwritten by merge`. By removing the files stated in the message, I could pull master properly, then it would merge. Your answer was the tip required to realise master wasn't what I thought it was. – JsAndDotNet Jan 29 '21 at 10:23
  • I was working on currentBranch. I ran "git fetch" to pull the latest changes for otherBranch. Then I ran "git checkout otherBranch" and ran "git pull". Now I will run "git checkout currentBranch" and run "git merge otherBranch" – RedEye Aug 15 '23 at 22:38
63

Say you have a branch master with the following commit history:

A -- B -- C -- D

Now, you create a branch test, work on it, and do 4 commits:


                 E -- F -- G -- H
                /
A -- B -- C -- D

master's head points to D, and test's head points to H.

The "Already up-to-date" message shows up when the HEAD of the branch you are merging into is a parent of the chain of commits of the branch you want to merge. That's the case, here: D is a parent of E.

There is nothing to merge from test to master, since nothing has changed on master since then. What you want to do here is literally to tell Git to have master's head to point to H, so master's branch has the following commits history:

A -- B -- C -- D -- E -- F -- G -- H

This is a job for Git command reset. You also want the working directory to reflect this change, so you'll do a hard reset:

git reset --hard H
Marek Stanley
  • 1,175
  • 10
  • 6
  • 6
    I've been told in the past that using `git reset --hard` is quite a drastic thing to do, can it lose commits? Is there a safer way of making these changes, or are the dangers of `git reset --hard` overstated? – Graham R. Armstrong Apr 08 '15 at 13:13
  • 2
    This command is sane, no worries. I would say the only thing to pay attention to with the `--hard` option is the fact that it actually modifies your working directory, and as a consequence, you lose uncommited changes. Personally, I do a `git status` before and after every manually-run git command to make sure my repo is clean or in the expected state. – Marek Stanley Apr 08 '15 at 15:27
  • 1
    this will produce "Your branch and 'origin/master' have diverged" status message, how can I resolve it? – Eido95 Mar 24 '17 at 10:47
  • 1
    Is there any need for the `--hard` option? I've been in this situation a couple times now and always reset without `--hard`. It worked just fine without the risk of losing any uncommitted changes. – Janosh Jan 19 '20 at 20:48
  • To @Casimir, you are right, you do not need to use `--hard`. If you do not define that, `git reset --mixed` will be used. That means that HEAD points to another commit and all other previous changes stay unstaged. A good explanation is here [here](https://stackoverflow.com/questions/3528245/whats-the-difference-between-git-reset-mixed-soft-and-hard) – Vaclav Vlcek Jun 28 '22 at 12:51
  • This command gives me: fatal: ambiguous argument 'H': unknown revision or path not in the working tree. – Stepan Yakovenko Mar 27 '23 at 23:12
34

This is what works for me. Let's say you have branch1 and you want to merge it into branch2.

You open git command line go to root folder of branch2 and type:

git checkout branch1
git pull branch1
git checkout branch2
git merge branch1
git push

If you have conflicts, solve them before git push.

user5305519
  • 3,008
  • 4
  • 26
  • 44
Stefan Pintilie
  • 677
  • 8
  • 5
  • 4
    in git merge branch 1 I am getting ---> `Already up to date. Merge made by the 'recursive' strategy.`. But before in branch 1 i did `git pull` , then all changes got pulled. What to do ? – Optimist Rohit Dec 08 '21 at 10:42
16

git merge origin/master instead git merge master worked for me. So to merge master into feature branch you may use:

git checkout feature_branch
git merge origin/master
Justinas Jakavonis
  • 8,220
  • 10
  • 69
  • 114
14

Be sure to checkout the branch you want to merge first and then pull it (so your local version matches the remote version).

Then checkout back to your branch you want to do the merge on and your git merge should work.

John Murphy
  • 329
  • 3
  • 10
  • 1
    This was it for me - I did a pull while in master; got to know that I got new commits in "branch". Tried to merge "branch" into master - "Already up to date". Did git checkout "branch" - got "Your branch is behind... and can be fast-forwarded.", which means I needed to update "branch" by running `git pull` while in the "branch" – sdbbs Mar 17 '20 at 10:48
7

This happens because your local copy of the branch you want to merge is out of date. I've got my branch, called MyBranch and I want to merge it into ProjectMaster.

_>git status
On branch MyBranch-Issue2
Your branch is up-to-date with 'origin/MyBranch-Issue2'.

nothing to commit, working tree clean

_>git merge ProjectMaster
Already up-to-date.

But I know that there are changes that need to be merged!

Here's the thing, when I type git merge ProjectMaster, git looks at my local copy of this branch, which might not be current. To see if this is the case, I first tell Git to check and see if my branches are out of date and fetch any changes if so using, uh, fetch. Then I hop into the branch I want to merge to see what's happening there...

_>git fetch origin

_>git checkout ProjectMaster
Switched to branch ProjectMaster
**Your branch is behind 'origin/ProjectMaster' by 85 commits, and can be fast-forwarded.**
  (use "git pull" to update your local branch)

Ah-ha! My local copy is stale by 85 commits, that explains everything! Now, I Pull down the changes I'm missing, then hop over to MyBranch and try the merge again.

_>git pull
Updating 669f825..5b49912
Fast-forward

_>git checkout MyBranch-Issue2
Switched to branch MyBranch-Issue2
Your branch is up-to-date with 'origin/MyBranch-Issue2'.

_>git merge ProjectMaster
Auto-merging Runbooks/File1.ps1
CONFLICT (content): Merge conflict in Runbooks/Runbooks/File1.ps1

Automatic merge failed; fix conflicts and then commit the result.

And now I have another issue to fix...

FoxDeploy
  • 12,569
  • 2
  • 33
  • 48
6

happend to me and was sent to this page, not sure if I had the same scenario, but mine was me trying to "re-merge" that "test" branch.

So I previously merged it but I intentionally exclude some specific changes during that merge, so it clearly has some diff between branches. I was then trying to re-merge it because I realize/forget that I should have and wanted to add a particular change/file that I have previously excluded and I was hoping if I do a merge again would show all changes that I excluded before, but I was wrong and I get the "Already up-to-date" message instead.

Upon reading @Bombe's comment/answer, he is right, and git I think behaves that way, so what I did was to make hard backup of the files on test branch, then checkout the master branch and manually paste the files in it and commit it as if it was new changes.

am not sure if this is the right way or could help others having this same issue, but it did provide solution to my particular case.

bubjavier
  • 982
  • 8
  • 11
  • Same situation here. The scenario is that I want to split an "integration" branch back to multiple "feature" branch. – Yadli Feb 23 '17 at 06:25
  • 5
    Instead of manual paste, you can checkout files directly from one branch into current branch: `git checkout srcBranch -- path/to/file`. Can use file globs too. – Todd Apr 20 '18 at 16:45
  • 1
    Thanks, I used your checkout method, but I put `checkout srcBranch -- *` and then looked at my diffs – benathon Aug 10 '18 at 08:26
  • I'm surprised that this answer doesn't have more upvotes. I'd suppose that the problem it describes is very common. – Josenaldo Jan 17 '23 at 17:25
6

A merge is always between the current HEAD and one or more commits (usually, branch head or tag),
and the index file must match the tree of HEAD commit (i.e. the contents of the last commit) when it starts out.
In other words, git diff --cached HEAD must report no changes.

The merged commit is already contained in HEAD. This is the simplest case, called "Already up-to-date."

That should mean the commits in test are already merged in master, but since other commits are done on master, git diff test would still give some differences.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
5

This happened to me because strangely GIT thought that the local branch was different from the remote branch. This was visible in the branch graph: it displayed two different branches: remotes/origin/branch_name and branch_name.

The solution was simply to remove the local repo and re-clone it from remote. This way GIT would understand that remotes/origin/branch_name>and branch_name are indeed the same, and I could issue the git merge branch_name.

rm <my_repo>
git clone <my_repo>
cd <my_repo>
git checkout <branch_name>
git pull
git checkout master
git merge <branch_name>
cdupont
  • 1,138
  • 10
  • 17
cdupont
  • 51
  • 1
  • 1
  • Isn't this the exact same answer as Acarter's? – Andrew C Oct 27 '14 at 04:43
  • I think Acarter actually missed the point -- there weren't any changes on the remote -- that wasn't the problem at all. I needed to "git checkout master" and then "git merge " to force the fast-forward merge. The other way around didn't do anything since the branch was ahead of master. Bombe's answer is a nice explanation but never answered the "how do I resolve it" part of the question. – MrMas Sep 28 '18 at 21:28
3

If merging branch A into branch B reports "Already up to date", reverse is not always true. It is true only if branch B is descendant of branch A, otherwise branch B simply can have changes that aren't in A.

Example:

  1. You create branches A and B off master
  2. You make some changes in master and merge these changes only into branch B (not updating or forgetting to update branch A).
  3. You make some changes in branch A and merge A to B.

At this point merging A to B reports "Already up to date" but the branches are different because branch B has updates from master while branch A does not.

Stan Bashtavenko
  • 1,025
  • 11
  • 16
2

Faced this scenario using Git Bash.

Our repository has multiple branches and each branch has a different commit cycle and merge happens once in a while. Old_Branch was used as a parent for New_Branch

Old_Branch was updated with some changes which required to be merged with New_Branch

Was using below pull command without any branch to get all sources from all branches.

git pull origin

Strangely this doesn't pull all the commits from all the branches. Had thought it so as the indicated shows almost all branches and tags.

So to fix this had checked out the Old_Branch pulled the latest using

git checkout Old_Branch

git pull origin Old_Branch

Now checked out New_Branch

git checkout New_Branch

Pulled it to be sure

git pull origin New_Branch

git merge Old_Branch

And viola got conflicts to fix from Old_Branch to New_Branch :) which was expected

Community
  • 1
  • 1
satlead
  • 21
  • 1
1

I had the same problem. I had changes in the remote and it was still showing "Already up to date". Recloning the repository fixed the problem for me.

Mohammad Rayan
  • 312
  • 3
  • 11
1

This may seem trivial but I have seen many people miss it and just do git merge while on the parent branch. This will automatically result to "Already up-to-date" message.

The merge command should be git merge branchNametoMergeFrom

For instance assumming you have 2 branches branchA & branchB and you need to merge B into A. You need to first checkout to BranchA and then use the merge command while specifing the branch to merge from in this case branchB.

Therefore the command should NOT be just git merge but should BE git merge branchB.

Tonnie
  • 4,865
  • 3
  • 34
  • 50
1

Here is the way to get the changes from another branch regardless of merge history (CAREFUL: this clears the working tree, so git stash or commit changes before trying this)

// stash changes to ensure you don't lose any edits
git checkout your-branch-that-won't-simply-merge
git stash


git checkout branch-with-changes -- .

The -- . argument for git checkout will checkout all the FILES from the other branch, while still checked out into the same branch. Then you can add and commit as you like.

I also used this in conjunction with git add -p Which will make you able to stage any changes in "hunks." It asks y/n if you want to stage any hunks of lines that changed, meaning you can leave unwanted changes out of your next commit.

Here's the link to the original answer I found, go give it a like.: https://stackoverflow.com/a/15536640/8272035

89 upvotes "checkout by providing the current path, .:

git checkout other-branch-name -- .

This operation is similar to switching HEAD to another branch without checking out files, but just from the "other direction".

As @김민준 mentions, this overwrites any uncommitted changes. Remember to either stash or commit them somewhere first if needed." by @Kache

0

The same happened to me. But the scenario was a little different, I had master branch, and I carved out release_1 (say) out of it. Made some changes in release_1 branch and merged it into origin. then I did ssh and on the remote server I again checkout out release_1 using the command git checkout -b release_1 - which actually carves out a new branch release_! from the master rather than checking out the already existing branch release_1 from origin. Solved the problem by removing "-b" switch

Deepika Anand
  • 305
  • 3
  • 6
0

Silly but it might happen. Suppose your branch name is prefixed with an issue reference (for example #91-fix-html-markup), if you do this merge:

$ git merge #91-fix-html-markup

it will not work as intended because everything after the # is ignored, because # starts an inline comment.

In this case you can rename the branch omitting # or use single quotes to surround the branch name: git merge '#91-fix-html-markup'.

Paolo
  • 20,112
  • 21
  • 72
  • 113
0

I committed the changes in my current branch, and then the merge from the Origin branch worked.

Graham Laight
  • 4,700
  • 3
  • 29
  • 28
0

I've fixed such problem with rebasing current branch on itself.

Zaporozhchenko Oleksandr
  • 4,660
  • 3
  • 26
  • 48
0

I'm not sure exactly what the problem was in my case, but the root of the issue seemed to be that with branchB checked out, I could not pull the latest changes from branchA...

I had to checkout branchA, pull, then checkout branchB and merge branchA for it to work like expected.

conner.xyz
  • 6,273
  • 8
  • 39
  • 65
0

try following commands

git checkout master
git pull
git fetch --all
git rebase --abort

git checkout test
git pull
git reset --hard  
git merge origin master

Mostly with rebase or already taking merge branch has shadow history, with clearing or reseting branch will help to get the merge things in files.

Anupam Maurya
  • 1,927
  • 22
  • 26
0

I have a way of re-merging it, my scenario is that I need to merge a release branch to master.

Condition: the release branch code is golden. meaning master is incorrect while release branch is correct.

Symptom: When merge release to master, the incorrect part in master is not updated with the parts in release.

here is the steps, disclaimer: my knowledge of git is limited, there must be a better way of achieving it.

  1. checkout release branch, do a pull. [Commit #A]
  2. merge latest master to release [Commit #B] (incorrect file will write to release branch)
  3. do a reverse commit of the [Commit #B] BUT keep it in stage (if the reserve commit is committed as [Commit #C] then do a soft reset to Commit #B) (this essentially reverse the incorrect files)
  4. edit the files, check whether these are correct, discard the unwanted ones (if there is any)
  5. stash the changes in step 4 [Stash{X}]
  6. reset release back to Commit #A (same as remote)
  7. merge latest master to release again [Commit #D] (diff hash should be the same but commit hash is different than b)
  8. Apply stash {x}
  9. Commit and merge to master.

EDIT: step 9 can happen at local just to see whether the intended parts has been applied if you happen to have to use a pr at remote.

Zzy
  • 35
  • 1
  • 7
-1

Hi, I have created a git alias that I called git remerge that helps to solve the problem.

  1. It will first git merge <FEATURE-BRANCH-NAME>.
  2. And then will force to re-calculate all the conflicts of the files that differ between the branches.

You are able to use it here!

If you have any suggestions or you want to contribute to the project, you are more than welcome!