trouble w/ pushing commits -- "failed to push some refs"



Robert Dodier <robert.dodier at gmail.com> writes:

> Hi,
>
> I've made several commits to my local Git repo (hope I'm
> using the right terminology there) and I am trying to push them.
> When I try
>
>   git push origin master
>
> I get this message:
>
> To ssh://robert_dodier at maxima.git.sourceforge.net/gitroot/maxima/maxima
>  ! [rejected]        master -> master (non-fast forward)
> error: failed to push some refs to
> 'ssh://robert_dodier at maxima.git.sourceforge.net/gitroot/maxima/maxima'
>
> I gather the stuff I have is out of date wrt the SF repo, right?
> Now how shall I resolve that -- I gather that I could rebase,
> but that would throw away the history, which I'd rather not
> have to recreate. How can I bring my repo up to date without
> throwing away the commit history? Or maybe it's actually
> some other problem?
>
> Thanks for any info. Yes, I have browsed various manuals
> and tutorials and I still don't understand what's going on.
> Sorry about that.
>
> best
>
> Robert Dodier

Hi Robert,

Rebasing does not throw away your commit history, unless
you tell it to. Rather, it reorders the history of one branch
relative to another. I think you likely need to do something
like

git checkout master
git fetch
git rebase --interactive --onto FETCH_HEAD

This will bring your repo's origin/master up-to-date with
the SF repo, then the interactive rebase will allow you
to rebase your master branch onto origin/master. The 'interactive'
bit means git will pop you into an editor's buffer with a list of the
commits (and summary), and some text about what you can do with
each. Once you exit that buffer, git will re-apply the commits
until it hits a conflict, at which point you will need to manually
resolve the conflict, then do

git add file
git rebase --continue

If you get in a pickle, you can do

git rebase --abort

I would recommend you create a copy of your repo before you start
experimenting.

Leo