Home > other >  Git merge says already up-to-date with master but my branch doesn’t contain the latest changes
Git merge says already up-to-date with master but my branch doesn’t contain the latest changes

Time:10-04

I’m working on a branch “ABC” cloned from master and since someone’s changes just got merged to master branch my code needs their latests changes. I used git merge and sent everything in a new commit, However, when I use hit pull, git merge, and fetch it says “already up-to-date”, not sure if I did something wrong but my code isn’t synced with what’s on master.

Git status says “Your branch is up to date with origin/feature/ABC”

Ps: I can’t modify master without approval, so preferably I’d like to not mess with master if possible

CodePudding user response:

git pull means:

  1. run git fetch, then
  2. run a second Git command, git merge by default, but you can set things up to be different if you like.

If you run it with no arguments (as you presumably did), this means:

  • git fetch origin (usually and in your case), and then
  • git merge HEAD@{upstream} (assuming your chosen second command is git merge).

The upstream is a setting, per-branch: you can change it if you want, but that's not what you want here. Your git status output shows that the upstream of your feature/ABC is your origin/feature/ABC, which is correct.

But what this all means is:

  • the git fetch step obtains all the new commits, including those on their master branch, so that your origin/master is updated, and then
  • the git merge step merges with the old commits you already had all along on your origin/feature/ABC that corresponds to your feature/ABC.

Hence, git pull is not what you want!

What you want, presumably, is:

  1. run git fetch or git fetch origin; then
  2. run git merge origin/master.

As you're a Git newbie, I recommend avoiding git pull. Run separate git fetch and second-command steps, so that you know exactly which step failed if one step does fail. This is important later when it comes to recovering from this failure.

If you prefer to run git pull, though, the combined convenience form is—partly for historical reasons—git pull origin master, rather than git pull origin origin/master, even though you want the merge step to use origin/master.

CodePudding user response:

Try git status to see the status of branch and master

  • Related