Git click rejected

I give up! Whenever I try to click, I get nonsense:

! [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 creating private branches, I now found our main repository (on github) to create my own copy.

At some point, I did the following:

 $ 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 over and make some changes to my upstreammaster branch, and PULL from the "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 greatly appreciated! If you need clarification, ask, I will answer!

+52
git push
Mar 06 '09 at 20:16
source share
7 answers

When clicking, try specifying refspec for the master:

 git push upstream upstreammaster:master 
+19
Mar 06 '09 at 20:31
source share

Yarret Hardy is right. Or first merge your changes back into the wizard, and then try clicking. By default, git push pushes all branches with names that correspond to the remote ones - and no other. So, these are your two options - either specify it explicitly as Jarret, or return to the general branch, and then click.

This was mentioned in the list of Git email messages, and it is clear that this will not change soon - many developers rely on this behavior in their workflows.

Edit / Explain

Assuming the upstreammaster branch is ready to push, you can do this:

  • Pull any changes from the upstream.

    $ Git pull upstream master

  • Switch to my local branch

    $ Git verification wizard

  • Merge changes with upstreammaster

    $ Git merge upstreammaster

  • Push my changes up

    $ Git push upstream

Another thing you might want to do before clicking is to rebase your changes against upstream / rebase so that your commits are together. You can do this 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 )

+16
Mar 06 '09 at 23:47
source share

First try to extract from the same refspec that you are trying to click on.

If this does not work, you can force git push use git push -f <repo> <refspec> , but be careful: this method can remove links in the remote repository.

+12
Mar 06 '09 at 20:37
source share

First use

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

and then try

 git push -u origin master 
+12
Feb 18 '14 at 13:03
source share

Is your upstream repository an open repository? I have the same error, but when I switch to naked, they no longer occur.

+3
Jun 22 2018-11-11T00:
source share

If the push request shows Rejected, try first pulling the data from your github account, and then try push.

Example:

In my case, it was an error-

  ! [rejected] master -> master (fetch first) error: failed to push some refs to 'https://github.com/ashif8984/git-github.git' hint: Updates were rejected because the remote contains work that you do hint: not have locally. This is usually caused by another repository pushing hint: to the same ref. You may want to first integrate the remote changes hint: (eg, 'git pull ...') before pushing again. hint: See the 'Note about fast-forwards' in 'git push --help' for details. 

**** So what I did was- ****

 $ git pull $ git push 

And the code was successfully added to my Github account.

0
Aug 26 '18 at 7:23
source share

If nothing works, try:

 git pull --allow-unrelated-histories <repo> <branch> 

then do:

 git push --set-upstream origin master 
0
Sep 18 '19 at 2:33
source share



All Articles