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:
- run
git fetch
, then - 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 thengit merge HEAD@{upstream}
(assuming your chosen second command isgit 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 theirmaster
branch, so that yourorigin/master
is updated, and then - the
git merge
step merges with the old commits you already had all along on yourorigin/feature/ABC
that corresponds to yourfeature/ABC
.
Hence, git pull
is not what you want!
What you want, presumably, is:
- run
git fetch
orgit fetch origin
; then - 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