6

I'm working on a Git repository, I had my branch (called jviotti) and my changes were merged to Master. Now, after commiting some changes, I found myself unabled to push to my branch.

$ git push origin jviotti
To https://github.com/jorisbontje/pikapay-frontend.git
 ! [rejected]        jviotti -> jviotti (non-fast-forward)
error: failed to push some refs to 'https://github.com/jorisbontje/pikapay-frontend.git'
To prevent you from losing history, non-fast-forward updates were rejected
Merge the remote changes (e.g. 'git pull') before pushing again.  See the
'Note about fast-forwards' section of 'git push --help' for details.

I tried then git pull:

$ git pull
You asked me to pull without telling me which branch you
want to rebase against, and 'branch.jviotti.merge' in
your configuration file does not tell me, either. Please
specify which branch you want to use on the command line and
try again (e.g. 'git pull <repository> <refspec>').
See git-pull(1) for details.

If you often rebase against the same branch, you may want to
use something like the following in your configuration file:

    [branch "jviotti"]
    remote = <nickname>
    merge = <remote-ref>
    rebase = true

    [remote "<nickname>"]
    url = <url>
    fetch = <refspec>

See git-config(1) for details.

After browsing a similar question here at SO, i tried:

$ git pull origin master:jviotti
From https://github.com/jorisbontje/pikapay-frontend
 ! [rejected]        master     -> jviotti  (non-fast-forward)

I thought that would do the trick. What am I missing?

2
  • 1
    Did you try git pull origin jviotti? Commented Dec 8, 2012 at 23:34
  • When you do git branch, what do you see? Commented Dec 9, 2012 at 0:26

1 Answer 1

4

You should first of all make sure your local branch has the upstream branch has its upstream.

git branch --set-upstream-to jviotti origin/jviotti
# or
git branch -u jviotti origin/jviotti

That is because the new default push policy will be "simple".

Once that is done:

git pull --rebase origin jviotti

That can replay your master history on top of the origin/jviotti (as in "What does it mean when git pull causes a conflict but git pull --rebase doesn't?").

But after that, as in "git pull --rebase upstream & git push origin rejects non-fast-forward?", you might still need a:

git push --force origin jviotti

The other option is to reset the local repo, as the OP jviotti comments:

I just cloned the repo again, change branch and It worked nice.
Awfull git nightmare, everything OK now.

4
  • It sort of looks like he's using local master for upstream jviotti - is this possible? Commented Dec 9, 2012 at 0:31
  • @EricWalker not on the first push: jviotti -> jviotti (non-fast-forward) means local jviotti has diverged. I make sure that local branch has the right upstream one. I agree the git pull origin master:jviottilooks shady, but might be inspired by following another SO answer a bit too closely.
    – VonC
    Commented Dec 9, 2012 at 0:33
  • Well I Did git pull --rebase origin jviotti and it worked but It inserted weird chars in my code and broke everything. Then I just cloned the repo again, change branch and It worked nice. Awfull git nightmare, everything OK now. Thanks
    – jviotti
    Commented Dec 9, 2012 at 1:32
  • @jviotti: if you ever find yourself in a mess, check out git reflog. You can generally reset --hard to any previous commit provided git gc has not been run. Commented Dec 9, 2012 at 2:39

Not the answer you're looking for? Browse other questions tagged or ask your own question.