Reputation: 18909
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?
Upvotes: 6
Views: 11580
Reputation: 1323115
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.
Upvotes: 4