git push rejected












50














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!










share|improve this question
























  • @drozzy: Do you know why Git does not accept your command? Your command once worked for me. After I moved Git to another folder in my Mac, I get a similar error message.
    – Léo Léopold Hertz 준영
    Apr 7 '09 at 19:49










  • no sorry i don't know. Right now I mostly do "git push upstream master", after having merged my other branch into upstreammaster.
    – drozzy
    Apr 7 '09 at 21:13










  • See also Git push non-fast-forward updates were rejected.
    – user456814
    May 18 '14 at 17:06












  • Check your folder permissions on the git-servers repo folder for write-access (also for subdirectories!)
    – xcy7e 웃
    May 17 '17 at 10:26










  • git push can be rejected if you have two branches with similar name, in my case my second branch was named: branch1.name()+ '/specification'. Git rejected it and i solved my problem thanks to @Pat Notz
    – Jannis
    Oct 19 at 15:23


















50














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!










share|improve this question
























  • @drozzy: Do you know why Git does not accept your command? Your command once worked for me. After I moved Git to another folder in my Mac, I get a similar error message.
    – Léo Léopold Hertz 준영
    Apr 7 '09 at 19:49










  • no sorry i don't know. Right now I mostly do "git push upstream master", after having merged my other branch into upstreammaster.
    – drozzy
    Apr 7 '09 at 21:13










  • See also Git push non-fast-forward updates were rejected.
    – user456814
    May 18 '14 at 17:06












  • Check your folder permissions on the git-servers repo folder for write-access (also for subdirectories!)
    – xcy7e 웃
    May 17 '17 at 10:26










  • git push can be rejected if you have two branches with similar name, in my case my second branch was named: branch1.name()+ '/specification'. Git rejected it and i solved my problem thanks to @Pat Notz
    – Jannis
    Oct 19 at 15:23
















50












50








50


20





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!










share|improve this question















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!







git push






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Apr 7 '09 at 19:50









Léo Léopold Hertz 준영

45.9k130383598




45.9k130383598










asked Mar 6 '09 at 20:16









drozzy

21.2k38133235




21.2k38133235












  • @drozzy: Do you know why Git does not accept your command? Your command once worked for me. After I moved Git to another folder in my Mac, I get a similar error message.
    – Léo Léopold Hertz 준영
    Apr 7 '09 at 19:49










  • no sorry i don't know. Right now I mostly do "git push upstream master", after having merged my other branch into upstreammaster.
    – drozzy
    Apr 7 '09 at 21:13










  • See also Git push non-fast-forward updates were rejected.
    – user456814
    May 18 '14 at 17:06












  • Check your folder permissions on the git-servers repo folder for write-access (also for subdirectories!)
    – xcy7e 웃
    May 17 '17 at 10:26










  • git push can be rejected if you have two branches with similar name, in my case my second branch was named: branch1.name()+ '/specification'. Git rejected it and i solved my problem thanks to @Pat Notz
    – Jannis
    Oct 19 at 15:23




















  • @drozzy: Do you know why Git does not accept your command? Your command once worked for me. After I moved Git to another folder in my Mac, I get a similar error message.
    – Léo Léopold Hertz 준영
    Apr 7 '09 at 19:49










  • no sorry i don't know. Right now I mostly do "git push upstream master", after having merged my other branch into upstreammaster.
    – drozzy
    Apr 7 '09 at 21:13










  • See also Git push non-fast-forward updates were rejected.
    – user456814
    May 18 '14 at 17:06












  • Check your folder permissions on the git-servers repo folder for write-access (also for subdirectories!)
    – xcy7e 웃
    May 17 '17 at 10:26










  • git push can be rejected if you have two branches with similar name, in my case my second branch was named: branch1.name()+ '/specification'. Git rejected it and i solved my problem thanks to @Pat Notz
    – Jannis
    Oct 19 at 15:23


















@drozzy: Do you know why Git does not accept your command? Your command once worked for me. After I moved Git to another folder in my Mac, I get a similar error message.
– Léo Léopold Hertz 준영
Apr 7 '09 at 19:49




@drozzy: Do you know why Git does not accept your command? Your command once worked for me. After I moved Git to another folder in my Mac, I get a similar error message.
– Léo Léopold Hertz 준영
Apr 7 '09 at 19:49












no sorry i don't know. Right now I mostly do "git push upstream master", after having merged my other branch into upstreammaster.
– drozzy
Apr 7 '09 at 21:13




no sorry i don't know. Right now I mostly do "git push upstream master", after having merged my other branch into upstreammaster.
– drozzy
Apr 7 '09 at 21:13












See also Git push non-fast-forward updates were rejected.
– user456814
May 18 '14 at 17:06






See also Git push non-fast-forward updates were rejected.
– user456814
May 18 '14 at 17:06














Check your folder permissions on the git-servers repo folder for write-access (also for subdirectories!)
– xcy7e 웃
May 17 '17 at 10:26




Check your folder permissions on the git-servers repo folder for write-access (also for subdirectories!)
– xcy7e 웃
May 17 '17 at 10:26












git push can be rejected if you have two branches with similar name, in my case my second branch was named: branch1.name()+ '/specification'. Git rejected it and i solved my problem thanks to @Pat Notz
– Jannis
Oct 19 at 15:23






git push can be rejected if you have two branches with similar name, in my case my second branch was named: branch1.name()+ '/specification'. Git rejected it and i solved my problem thanks to @Pat Notz
– Jannis
Oct 19 at 15:23














6 Answers
6






active

oldest

votes


















19














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



git push upstream upstreammaster:master





share|improve this answer

















  • 1




    This works for some reason...
    – drozzy
    Mar 9 '09 at 12:01






  • 3




    @Jarret: It does not work for me. My code $git push git@github.com:user/repo.git git@github.com:user/repo.git:master.
    – Léo Léopold Hertz 준영
    Apr 7 '09 at 19:44










  • Masi, try without using the full URL on the second parameter: git push it@github.com:user/repo.git master
    – Jarret Hardie
    Apr 7 '09 at 22:55










  • doesn't work for me
    – neoneye
    Jan 27 '12 at 8:55










  • how to do this on zend studio?
    – albanx
    Aug 6 '13 at 16:02



















17














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:





  1. Pull in any changes from the upstream.



    $ git pull upstream master




  2. Switch to my local master branch



    $ git checkout master




  3. Merge changes in from upstreammaster



    $ git merge upstreammaster




  4. 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)






share|improve this answer























  • How do you mean "merge back to a common branch and then push"? Which is the common branch in this case?
    – drozzy
    Mar 9 '09 at 12:02










  • I had the same problem after checking out and working on a branch, and pushing changes that included an update to a file that had been deleted in the master branch (which I had not touched at all). Another developer tried some Git commands I didn't catch, but the problem remained: git status showed that my branch was clean, git pull did nothing, but the command git push still output error: failed to push some refs.... I finally got the problem fixed like this: 1. git checkout master, 2. git pull, and 3. git checkout the_branch_name.
    – Teemu Leisti
    Sep 12 '12 at 8:01












  • er... well, and what happens when you do the first command (git pull upstream master) and you have a conflict in the pull??? You have to solve the conflict before going on??
    – Raul Luna
    Jun 11 '13 at 13:55





















13














First, attempt to pull from the same refspec that you are trying to push to.



If this does not work, you can force a git push by using git push -f <repo> <refspec>, but use caution: this method can cause references to be deleted on the remote repository.






share|improve this answer





























    7














    First use



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


    and then try



    git push -u origin master





    share|improve this answer































      3














      Is your repository at "upstream" a bare repository? I got the same error, but when I change to bare they no longer happen.






      share|improve this answer





















      • awesome, this is exactly what was causing my problem, thanks for the answer!
        – adamc
        Oct 10 '12 at 9:32



















      0














      If push request is shows Rejected, then try first pull from your github account and then try push.



      Ex:



      In my case it was giving 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: (e.g., '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 pushed successfully into my Github Account.






      share|improve this answer























      • This does not provide an answer to the question. Once you have sufficient reputation you will be able to comment on any post; instead, provide answers that don't require clarification from the asker. - From Review
        – Matthias
        Aug 26 at 9:00











      Your Answer






      StackExchange.ifUsing("editor", function () {
      StackExchange.using("externalEditor", function () {
      StackExchange.using("snippets", function () {
      StackExchange.snippets.init();
      });
      });
      }, "code-snippets");

      StackExchange.ready(function() {
      var channelOptions = {
      tags: "".split(" "),
      id: "1"
      };
      initTagRenderer("".split(" "), "".split(" "), channelOptions);

      StackExchange.using("externalEditor", function() {
      // Have to fire editor after snippets, if snippets enabled
      if (StackExchange.settings.snippets.snippetsEnabled) {
      StackExchange.using("snippets", function() {
      createEditor();
      });
      }
      else {
      createEditor();
      }
      });

      function createEditor() {
      StackExchange.prepareEditor({
      heartbeatType: 'answer',
      autoActivateHeartbeat: false,
      convertImagesToLinks: true,
      noModals: true,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: 10,
      bindNavPrevention: true,
      postfix: "",
      imageUploader: {
      brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
      contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
      allowUrls: true
      },
      onDemand: true,
      discardSelector: ".discard-answer"
      ,immediatelyShowMarkdownHelp:true
      });


      }
      });














      draft saved

      draft discarded


















      StackExchange.ready(
      function () {
      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f620253%2fgit-push-rejected%23new-answer', 'question_page');
      }
      );

      Post as a guest















      Required, but never shown

























      6 Answers
      6






      active

      oldest

      votes








      6 Answers
      6






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      19














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



      git push upstream upstreammaster:master





      share|improve this answer

















      • 1




        This works for some reason...
        – drozzy
        Mar 9 '09 at 12:01






      • 3




        @Jarret: It does not work for me. My code $git push git@github.com:user/repo.git git@github.com:user/repo.git:master.
        – Léo Léopold Hertz 준영
        Apr 7 '09 at 19:44










      • Masi, try without using the full URL on the second parameter: git push it@github.com:user/repo.git master
        – Jarret Hardie
        Apr 7 '09 at 22:55










      • doesn't work for me
        – neoneye
        Jan 27 '12 at 8:55










      • how to do this on zend studio?
        – albanx
        Aug 6 '13 at 16:02
















      19














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



      git push upstream upstreammaster:master





      share|improve this answer

















      • 1




        This works for some reason...
        – drozzy
        Mar 9 '09 at 12:01






      • 3




        @Jarret: It does not work for me. My code $git push git@github.com:user/repo.git git@github.com:user/repo.git:master.
        – Léo Léopold Hertz 준영
        Apr 7 '09 at 19:44










      • Masi, try without using the full URL on the second parameter: git push it@github.com:user/repo.git master
        – Jarret Hardie
        Apr 7 '09 at 22:55










      • doesn't work for me
        – neoneye
        Jan 27 '12 at 8:55










      • how to do this on zend studio?
        – albanx
        Aug 6 '13 at 16:02














      19












      19








      19






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



      git push upstream upstreammaster:master





      share|improve this answer












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



      git push upstream upstreammaster:master






      share|improve this answer












      share|improve this answer



      share|improve this answer










      answered Mar 6 '09 at 20:31









      Jarret Hardie

      65.8k9111115




      65.8k9111115








      • 1




        This works for some reason...
        – drozzy
        Mar 9 '09 at 12:01






      • 3




        @Jarret: It does not work for me. My code $git push git@github.com:user/repo.git git@github.com:user/repo.git:master.
        – Léo Léopold Hertz 준영
        Apr 7 '09 at 19:44










      • Masi, try without using the full URL on the second parameter: git push it@github.com:user/repo.git master
        – Jarret Hardie
        Apr 7 '09 at 22:55










      • doesn't work for me
        – neoneye
        Jan 27 '12 at 8:55










      • how to do this on zend studio?
        – albanx
        Aug 6 '13 at 16:02














      • 1




        This works for some reason...
        – drozzy
        Mar 9 '09 at 12:01






      • 3




        @Jarret: It does not work for me. My code $git push git@github.com:user/repo.git git@github.com:user/repo.git:master.
        – Léo Léopold Hertz 준영
        Apr 7 '09 at 19:44










      • Masi, try without using the full URL on the second parameter: git push it@github.com:user/repo.git master
        – Jarret Hardie
        Apr 7 '09 at 22:55










      • doesn't work for me
        – neoneye
        Jan 27 '12 at 8:55










      • how to do this on zend studio?
        – albanx
        Aug 6 '13 at 16:02








      1




      1




      This works for some reason...
      – drozzy
      Mar 9 '09 at 12:01




      This works for some reason...
      – drozzy
      Mar 9 '09 at 12:01




      3




      3




      @Jarret: It does not work for me. My code $git push git@github.com:user/repo.git git@github.com:user/repo.git:master.
      – Léo Léopold Hertz 준영
      Apr 7 '09 at 19:44




      @Jarret: It does not work for me. My code $git push git@github.com:user/repo.git git@github.com:user/repo.git:master.
      – Léo Léopold Hertz 준영
      Apr 7 '09 at 19:44












      Masi, try without using the full URL on the second parameter: git push it@github.com:user/repo.git master
      – Jarret Hardie
      Apr 7 '09 at 22:55




      Masi, try without using the full URL on the second parameter: git push it@github.com:user/repo.git master
      – Jarret Hardie
      Apr 7 '09 at 22:55












      doesn't work for me
      – neoneye
      Jan 27 '12 at 8:55




      doesn't work for me
      – neoneye
      Jan 27 '12 at 8:55












      how to do this on zend studio?
      – albanx
      Aug 6 '13 at 16:02




      how to do this on zend studio?
      – albanx
      Aug 6 '13 at 16:02













      17














      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:





      1. Pull in any changes from the upstream.



        $ git pull upstream master




      2. Switch to my local master branch



        $ git checkout master




      3. Merge changes in from upstreammaster



        $ git merge upstreammaster




      4. 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)






      share|improve this answer























      • How do you mean "merge back to a common branch and then push"? Which is the common branch in this case?
        – drozzy
        Mar 9 '09 at 12:02










      • I had the same problem after checking out and working on a branch, and pushing changes that included an update to a file that had been deleted in the master branch (which I had not touched at all). Another developer tried some Git commands I didn't catch, but the problem remained: git status showed that my branch was clean, git pull did nothing, but the command git push still output error: failed to push some refs.... I finally got the problem fixed like this: 1. git checkout master, 2. git pull, and 3. git checkout the_branch_name.
        – Teemu Leisti
        Sep 12 '12 at 8:01












      • er... well, and what happens when you do the first command (git pull upstream master) and you have a conflict in the pull??? You have to solve the conflict before going on??
        – Raul Luna
        Jun 11 '13 at 13:55


















      17














      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:





      1. Pull in any changes from the upstream.



        $ git pull upstream master




      2. Switch to my local master branch



        $ git checkout master




      3. Merge changes in from upstreammaster



        $ git merge upstreammaster




      4. 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)






      share|improve this answer























      • How do you mean "merge back to a common branch and then push"? Which is the common branch in this case?
        – drozzy
        Mar 9 '09 at 12:02










      • I had the same problem after checking out and working on a branch, and pushing changes that included an update to a file that had been deleted in the master branch (which I had not touched at all). Another developer tried some Git commands I didn't catch, but the problem remained: git status showed that my branch was clean, git pull did nothing, but the command git push still output error: failed to push some refs.... I finally got the problem fixed like this: 1. git checkout master, 2. git pull, and 3. git checkout the_branch_name.
        – Teemu Leisti
        Sep 12 '12 at 8:01












      • er... well, and what happens when you do the first command (git pull upstream master) and you have a conflict in the pull??? You have to solve the conflict before going on??
        – Raul Luna
        Jun 11 '13 at 13:55
















      17












      17








      17






      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:





      1. Pull in any changes from the upstream.



        $ git pull upstream master




      2. Switch to my local master branch



        $ git checkout master




      3. Merge changes in from upstreammaster



        $ git merge upstreammaster




      4. 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)






      share|improve this answer














      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:





      1. Pull in any changes from the upstream.



        $ git pull upstream master




      2. Switch to my local master branch



        $ git checkout master




      3. Merge changes in from upstreammaster



        $ git merge upstreammaster




      4. 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)







      share|improve this answer














      share|improve this answer



      share|improve this answer








      edited Mar 9 '09 at 13:34

























      answered Mar 6 '09 at 23:47









      Pat Notz

      129k288089




      129k288089












      • How do you mean "merge back to a common branch and then push"? Which is the common branch in this case?
        – drozzy
        Mar 9 '09 at 12:02










      • I had the same problem after checking out and working on a branch, and pushing changes that included an update to a file that had been deleted in the master branch (which I had not touched at all). Another developer tried some Git commands I didn't catch, but the problem remained: git status showed that my branch was clean, git pull did nothing, but the command git push still output error: failed to push some refs.... I finally got the problem fixed like this: 1. git checkout master, 2. git pull, and 3. git checkout the_branch_name.
        – Teemu Leisti
        Sep 12 '12 at 8:01












      • er... well, and what happens when you do the first command (git pull upstream master) and you have a conflict in the pull??? You have to solve the conflict before going on??
        – Raul Luna
        Jun 11 '13 at 13:55




















      • How do you mean "merge back to a common branch and then push"? Which is the common branch in this case?
        – drozzy
        Mar 9 '09 at 12:02










      • I had the same problem after checking out and working on a branch, and pushing changes that included an update to a file that had been deleted in the master branch (which I had not touched at all). Another developer tried some Git commands I didn't catch, but the problem remained: git status showed that my branch was clean, git pull did nothing, but the command git push still output error: failed to push some refs.... I finally got the problem fixed like this: 1. git checkout master, 2. git pull, and 3. git checkout the_branch_name.
        – Teemu Leisti
        Sep 12 '12 at 8:01












      • er... well, and what happens when you do the first command (git pull upstream master) and you have a conflict in the pull??? You have to solve the conflict before going on??
        – Raul Luna
        Jun 11 '13 at 13:55


















      How do you mean "merge back to a common branch and then push"? Which is the common branch in this case?
      – drozzy
      Mar 9 '09 at 12:02




      How do you mean "merge back to a common branch and then push"? Which is the common branch in this case?
      – drozzy
      Mar 9 '09 at 12:02












      I had the same problem after checking out and working on a branch, and pushing changes that included an update to a file that had been deleted in the master branch (which I had not touched at all). Another developer tried some Git commands I didn't catch, but the problem remained: git status showed that my branch was clean, git pull did nothing, but the command git push still output error: failed to push some refs.... I finally got the problem fixed like this: 1. git checkout master, 2. git pull, and 3. git checkout the_branch_name.
      – Teemu Leisti
      Sep 12 '12 at 8:01






      I had the same problem after checking out and working on a branch, and pushing changes that included an update to a file that had been deleted in the master branch (which I had not touched at all). Another developer tried some Git commands I didn't catch, but the problem remained: git status showed that my branch was clean, git pull did nothing, but the command git push still output error: failed to push some refs.... I finally got the problem fixed like this: 1. git checkout master, 2. git pull, and 3. git checkout the_branch_name.
      – Teemu Leisti
      Sep 12 '12 at 8:01














      er... well, and what happens when you do the first command (git pull upstream master) and you have a conflict in the pull??? You have to solve the conflict before going on??
      – Raul Luna
      Jun 11 '13 at 13:55






      er... well, and what happens when you do the first command (git pull upstream master) and you have a conflict in the pull??? You have to solve the conflict before going on??
      – Raul Luna
      Jun 11 '13 at 13:55













      13














      First, attempt to pull from the same refspec that you are trying to push to.



      If this does not work, you can force a git push by using git push -f <repo> <refspec>, but use caution: this method can cause references to be deleted on the remote repository.






      share|improve this answer


























        13














        First, attempt to pull from the same refspec that you are trying to push to.



        If this does not work, you can force a git push by using git push -f <repo> <refspec>, but use caution: this method can cause references to be deleted on the remote repository.






        share|improve this answer
























          13












          13








          13






          First, attempt to pull from the same refspec that you are trying to push to.



          If this does not work, you can force a git push by using git push -f <repo> <refspec>, but use caution: this method can cause references to be deleted on the remote repository.






          share|improve this answer












          First, attempt to pull from the same refspec that you are trying to push to.



          If this does not work, you can force a git push by using git push -f <repo> <refspec>, but use caution: this method can cause references to be deleted on the remote repository.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Mar 6 '09 at 20:37









          Rob Watson

          1,97862838




          1,97862838























              7














              First use



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


              and then try



              git push -u origin master





              share|improve this answer




























                7














                First use



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


                and then try



                git push -u origin master





                share|improve this answer


























                  7












                  7








                  7






                  First use



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


                  and then try



                  git push -u origin master





                  share|improve this answer














                  First use



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


                  and then try



                  git push -u origin master






                  share|improve this answer














                  share|improve this answer



                  share|improve this answer








                  edited Nov 21 at 2:09









                  Pang

                  6,8601563101




                  6,8601563101










                  answered Feb 18 '14 at 13:03









                  user2368055

                  255410




                  255410























                      3














                      Is your repository at "upstream" a bare repository? I got the same error, but when I change to bare they no longer happen.






                      share|improve this answer





















                      • awesome, this is exactly what was causing my problem, thanks for the answer!
                        – adamc
                        Oct 10 '12 at 9:32
















                      3














                      Is your repository at "upstream" a bare repository? I got the same error, but when I change to bare they no longer happen.






                      share|improve this answer





















                      • awesome, this is exactly what was causing my problem, thanks for the answer!
                        – adamc
                        Oct 10 '12 at 9:32














                      3












                      3








                      3






                      Is your repository at "upstream" a bare repository? I got the same error, but when I change to bare they no longer happen.






                      share|improve this answer












                      Is your repository at "upstream" a bare repository? I got the same error, but when I change to bare they no longer happen.







                      share|improve this answer












                      share|improve this answer



                      share|improve this answer










                      answered Jun 22 '11 at 9:52









                      alekwisnia

                      1,44911633




                      1,44911633












                      • awesome, this is exactly what was causing my problem, thanks for the answer!
                        – adamc
                        Oct 10 '12 at 9:32


















                      • awesome, this is exactly what was causing my problem, thanks for the answer!
                        – adamc
                        Oct 10 '12 at 9:32
















                      awesome, this is exactly what was causing my problem, thanks for the answer!
                      – adamc
                      Oct 10 '12 at 9:32




                      awesome, this is exactly what was causing my problem, thanks for the answer!
                      – adamc
                      Oct 10 '12 at 9:32











                      0














                      If push request is shows Rejected, then try first pull from your github account and then try push.



                      Ex:



                      In my case it was giving 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: (e.g., '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 pushed successfully into my Github Account.






                      share|improve this answer























                      • This does not provide an answer to the question. Once you have sufficient reputation you will be able to comment on any post; instead, provide answers that don't require clarification from the asker. - From Review
                        – Matthias
                        Aug 26 at 9:00
















                      0














                      If push request is shows Rejected, then try first pull from your github account and then try push.



                      Ex:



                      In my case it was giving 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: (e.g., '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 pushed successfully into my Github Account.






                      share|improve this answer























                      • This does not provide an answer to the question. Once you have sufficient reputation you will be able to comment on any post; instead, provide answers that don't require clarification from the asker. - From Review
                        – Matthias
                        Aug 26 at 9:00














                      0












                      0








                      0






                      If push request is shows Rejected, then try first pull from your github account and then try push.



                      Ex:



                      In my case it was giving 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: (e.g., '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 pushed successfully into my Github Account.






                      share|improve this answer














                      If push request is shows Rejected, then try first pull from your github account and then try push.



                      Ex:



                      In my case it was giving 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: (e.g., '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 pushed successfully into my Github Account.







                      share|improve this answer














                      share|improve this answer



                      share|improve this answer








                      edited Aug 26 at 10:02









                      knittl

                      150k39227279




                      150k39227279










                      answered Aug 26 at 7:23









                      Ashif

                      11




                      11












                      • This does not provide an answer to the question. Once you have sufficient reputation you will be able to comment on any post; instead, provide answers that don't require clarification from the asker. - From Review
                        – Matthias
                        Aug 26 at 9:00


















                      • This does not provide an answer to the question. Once you have sufficient reputation you will be able to comment on any post; instead, provide answers that don't require clarification from the asker. - From Review
                        – Matthias
                        Aug 26 at 9:00
















                      This does not provide an answer to the question. Once you have sufficient reputation you will be able to comment on any post; instead, provide answers that don't require clarification from the asker. - From Review
                      – Matthias
                      Aug 26 at 9:00




                      This does not provide an answer to the question. Once you have sufficient reputation you will be able to comment on any post; instead, provide answers that don't require clarification from the asker. - From Review
                      – Matthias
                      Aug 26 at 9:00


















                      draft saved

                      draft discarded




















































                      Thanks for contributing an answer to Stack Overflow!


                      • Please be sure to answer the question. Provide details and share your research!

                      But avoid



                      • Asking for help, clarification, or responding to other answers.

                      • Making statements based on opinion; back them up with references or personal experience.


                      To learn more, see our tips on writing great answers.





                      Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


                      Please pay close attention to the following guidance:


                      • Please be sure to answer the question. Provide details and share your research!

                      But avoid



                      • Asking for help, clarification, or responding to other answers.

                      • Making statements based on opinion; back them up with references or personal experience.


                      To learn more, see our tips on writing great answers.




                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function () {
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f620253%2fgit-push-rejected%23new-answer', 'question_page');
                      }
                      );

                      Post as a guest















                      Required, but never shown





















































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown

































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown







                      Popular posts from this blog

                      404 Error Contact Form 7 ajax form submitting

                      How to know if a Active Directory user can login interactively

                      TypeError: fit_transform() missing 1 required positional argument: 'X'