Q:

git push rejected

I give up!
Whenever I try to push I get a stupid: 
! [rejected]        master -> master (non-fast forward)
error: failed to push some refs to 'git@github.com:companyX/projectX.git'

Our team has a new git setup. Instead of making private branches I now Forked our main repository (on github) to create my own copy.
At some point what I did was:
$ git fetch upstream master:upstreammaster

So here is my current setup::
$ git branch
master
* upstreammaster

$ git remote -v
origin  git@github.com:userX/projectX.git
upstream    git@github.com:companyX/projectX.git

where userX is my private repository.
So I go and make some changes to my upstreammaster branch, and the PULL from "upstream master".
Everything merges and stuff:
$ git pull upstream master
remote: Counting objects: 95, done.
remote: Compressing objects: 100% (60/60), done.
remote: Total 60 (delta 54), reused 0 (delta 0)
Unpacking objects: 100% (60/60), done.
From git@github.com:companyX/projectX
 * branch            master     -> FETCH_HEAD
Merge made by recursive.
stuff                      |  165 ++++++++++++--------
stuff                      |   35 ++--
stuff                       |  107 ++++++++++---
stuff                       |  105 ++++++++++---
stuff             |   24 ++--
stuff               |    9 +-
stuff                   |   53 +++----
stuff            |   44 +++---
stuff              |   52 +++----
stuff |   32 +----
stuff          |    4 +-
 stuff             |  138 ++++++++---------
stuff     |   58 ++++----
stuff    |  115 ++++++++------
stuff          |    5 +-
stuff                       |   39 ++---
stuff                        |   28 ++--
 17 files changed, 560 insertions(+), 453 deletions(-)

but then when I try to do:
$ git push upstream master
To git@github.com:companyX/projectX.git
 ! [rejected]        master -> master (non-fast forward)
error: failed to push some refs to 'git@github.com:companyX/projectX.git'

Any help would be greately appreciated! If you need clarification please ask, I will reply!

A:

When doing a push, try specifying the refspec for the upstream master:
git push upstream upstreammaster:master

A:

Jarret Hardie is correct.  Or, first merge your changes back into master and then try the push.  By default, git push pushes all branches that have names that match on the remote -- and no others.  So those are your two choices -- either specify it explicitly like Jarret said or merge back to a common branch and then push.
There's been talk about this on the Git mail list and it's clear that this behavior is not about to change anytime soon -- many developers rely on this behavior in their workflows.
Edit/Clarification
Assuming your upstreammaster branch is ready to push then you could do this:

Pull in any changes from the upstream.
$ git pull upstream master
Switch to my local master branch
$ git checkout master
Merge changes in from upstreammaster
$ git merge upstreammaster
Push my changes up
$ git push upstream

Another thing that you may want to do before pushing is to rebase your changes against upstream/master so that your commits are all together.  You can either do that as a separate step between #1 and #2 above (git rebase upstream/master) or you can do it as part of your pull (git pull --rebase upstream master)

A:

First use
git pull https://github.com/username/repository master

and then try
git push -u origin master

