Kyle Strand
Kyle Strand

Reputation: 16499

Newly created branch is not up-to-date with remote counterpart?

I am trying to update a fork of my project with the latest updates from the original project's master. (I'm not the maintainer of the fork, but the maintainer of the fork isn't familiar with Git and relies on me to do this for him.)

Previously, I have not had any trouble doing this, but now I'm finding that for some reason Git is telling me that pushing to his branch would be non-fast-forward, even though I'm creating my local branch based on the latest version of the remote master.

Using FORK as the remote fork name, and without actually performing the merge of the latest updates from the original project, here's what's happening:

> git fetch FORK
> git checkout -b fork_master FORK/master
Branch fork_master set up to track remote branch master from FORK.
Switched to a new branch 'fork_master'
> git push FORK master
To git@<fork-URL>.git
 ! [rejected]        master -> master (non-fast-forward)
error: failed to push some refs to 'git@<fork-URL>.git'
hint: Updates were rejected because a pushed branch tip is behind its remote
hint: counterpart. Check out this branch and integrate the remote changes
hint: (e.g. 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

As you can see, I fetch right before creating the branch, create the branch from FORK master, and then immediately push back to FORK master without making any changes.

Calling git fetch again produces no output (again), so the fork is not being updated in between my original fetch and my push.

I have tried deleting and re-establishing my remote corresponding to the FORK, but that has not changed the behavior.

What could possibly be going on here? I'm using git 2.1.4.

EDIT: As a workaround, I've created an entirely new clone with FORK as origin and the original as a separate remote. I encountered no problems with the merge-and-push when doing it this way. I'd still like to know why my original attempt failed, though.

Upvotes: 0

Views: 133

Answers (1)

torek
torek

Reputation: 489113

As the numbered user noted, you are requesting that git push the tip of your local master branch to the remote's master branch.

The reason is that in the syntax for git push remote refspec, the final argument is a "refspec", not just a branch name. Loosely speaking, a refspec is a pair of branch names, such as fork_master:master. For push, the left hand side name is your local branch tip, and the right hand side name is the name you ask the remote to update.

Writing a single branch name like master means, for git push, master:master.

(Everything is a bit different with fetch, where the left side matches the remote's names and the right side is your names, and omitting the right side of a refspec means "don't update anything, just drop the result into FETCH_HEAD".)

Upvotes: 1

Related Questions