git error: failed to push some refs to












239















For some reason, I can't push now, whereas I could do it yesterday.
Maybe I messed up with configs or something.



This is what happens:



When I use the git push origin master



gitbashscr



What my working directory and remote repository looks like:



enter image description here










share|improve this question




















  • 4





    looks like your local repo is not in sync with the git repo. did you try to do git pull ?

    – R11G
    Jun 9 '14 at 6:25






  • 1





    yes, but I have no idea with the following syntax after git pull it says git pull <remote> <branch>, can you let me see an example syntax for git pull?

    – hikki
    Jun 9 '14 at 6:29






  • 1





    Do check this similar question - stackoverflow.com/questions/18588974/…

    – R11G
    Jun 9 '14 at 6:33






  • 3





    @R11G thank you sir! this link helped me stackoverflow.com/a/18589043/3626672

    – hikki
    Jun 9 '14 at 6:42






  • 2





    I got that error on a new repo. This helped: stackoverflow.com/a/6518774/2067690

    – HumanInDisguise
    Jul 8 '15 at 20:38
















239















For some reason, I can't push now, whereas I could do it yesterday.
Maybe I messed up with configs or something.



This is what happens:



When I use the git push origin master



gitbashscr



What my working directory and remote repository looks like:



enter image description here










share|improve this question




















  • 4





    looks like your local repo is not in sync with the git repo. did you try to do git pull ?

    – R11G
    Jun 9 '14 at 6:25






  • 1





    yes, but I have no idea with the following syntax after git pull it says git pull <remote> <branch>, can you let me see an example syntax for git pull?

    – hikki
    Jun 9 '14 at 6:29






  • 1





    Do check this similar question - stackoverflow.com/questions/18588974/…

    – R11G
    Jun 9 '14 at 6:33






  • 3





    @R11G thank you sir! this link helped me stackoverflow.com/a/18589043/3626672

    – hikki
    Jun 9 '14 at 6:42






  • 2





    I got that error on a new repo. This helped: stackoverflow.com/a/6518774/2067690

    – HumanInDisguise
    Jul 8 '15 at 20:38














239












239








239


132






For some reason, I can't push now, whereas I could do it yesterday.
Maybe I messed up with configs or something.



This is what happens:



When I use the git push origin master



gitbashscr



What my working directory and remote repository looks like:



enter image description here










share|improve this question
















For some reason, I can't push now, whereas I could do it yesterday.
Maybe I messed up with configs or something.



This is what happens:



When I use the git push origin master



gitbashscr



What my working directory and remote repository looks like:



enter image description here







git github






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Feb 17 '15 at 15:01









Tshepang

6,1751772114




6,1751772114










asked Jun 9 '14 at 6:21









hikkihikki

1,69341017




1,69341017








  • 4





    looks like your local repo is not in sync with the git repo. did you try to do git pull ?

    – R11G
    Jun 9 '14 at 6:25






  • 1





    yes, but I have no idea with the following syntax after git pull it says git pull <remote> <branch>, can you let me see an example syntax for git pull?

    – hikki
    Jun 9 '14 at 6:29






  • 1





    Do check this similar question - stackoverflow.com/questions/18588974/…

    – R11G
    Jun 9 '14 at 6:33






  • 3





    @R11G thank you sir! this link helped me stackoverflow.com/a/18589043/3626672

    – hikki
    Jun 9 '14 at 6:42






  • 2





    I got that error on a new repo. This helped: stackoverflow.com/a/6518774/2067690

    – HumanInDisguise
    Jul 8 '15 at 20:38














  • 4





    looks like your local repo is not in sync with the git repo. did you try to do git pull ?

    – R11G
    Jun 9 '14 at 6:25






  • 1





    yes, but I have no idea with the following syntax after git pull it says git pull <remote> <branch>, can you let me see an example syntax for git pull?

    – hikki
    Jun 9 '14 at 6:29






  • 1





    Do check this similar question - stackoverflow.com/questions/18588974/…

    – R11G
    Jun 9 '14 at 6:33






  • 3





    @R11G thank you sir! this link helped me stackoverflow.com/a/18589043/3626672

    – hikki
    Jun 9 '14 at 6:42






  • 2





    I got that error on a new repo. This helped: stackoverflow.com/a/6518774/2067690

    – HumanInDisguise
    Jul 8 '15 at 20:38








4




4





looks like your local repo is not in sync with the git repo. did you try to do git pull ?

– R11G
Jun 9 '14 at 6:25





looks like your local repo is not in sync with the git repo. did you try to do git pull ?

– R11G
Jun 9 '14 at 6:25




1




1





yes, but I have no idea with the following syntax after git pull it says git pull <remote> <branch>, can you let me see an example syntax for git pull?

– hikki
Jun 9 '14 at 6:29





yes, but I have no idea with the following syntax after git pull it says git pull <remote> <branch>, can you let me see an example syntax for git pull?

– hikki
Jun 9 '14 at 6:29




1




1





Do check this similar question - stackoverflow.com/questions/18588974/…

– R11G
Jun 9 '14 at 6:33





Do check this similar question - stackoverflow.com/questions/18588974/…

– R11G
Jun 9 '14 at 6:33




3




3





@R11G thank you sir! this link helped me stackoverflow.com/a/18589043/3626672

– hikki
Jun 9 '14 at 6:42





@R11G thank you sir! this link helped me stackoverflow.com/a/18589043/3626672

– hikki
Jun 9 '14 at 6:42




2




2





I got that error on a new repo. This helped: stackoverflow.com/a/6518774/2067690

– HumanInDisguise
Jul 8 '15 at 20:38





I got that error on a new repo. This helped: stackoverflow.com/a/6518774/2067690

– HumanInDisguise
Jul 8 '15 at 20:38












19 Answers
19






active

oldest

votes


















358














If the GitHub repo has seen new commits pushed to it, while you were working locally, I would advise using:



git pull --rebase
git push


The full syntax is:



git pull --rebase origin master
git push origin master


That way, you would replay (the --rebase part) your local commits on top of the newly updated origin/master (or origin/yourBranch: git pull origin yourBranch).



See a more complete example in the chapter 6 Pull with rebase of the Git Pocket Book.



I would recommend a:



git push -u origin master


That would establish a tracking relationship between your local master branch and its upstream branch.

After that, any future push for that branch can be done with a simple:



git push


See "Why do I need to explicitly push a new branch?".





Since the OP already reset and redone its commit on top of origin/master:



git reset --mixed origin/master
git add .
git commit -m "This is a new commit for what I originally planned to be amended"
git push origin master


There is no need to pull --rebase.



Note: git reset --mixed origin/master can also be written git reset origin/master, since the --mixed option is the default one when using git reset.






share|improve this answer


























  • is it OK to execute your suggested git pull --rebase...? coz I already done > git reset --mixed origin/master > git add . > git commit -m "This is a new commit for what I originally planned to be an amendmend" > git push origin master suggested here stackoverflow.com/questions/18588974/… btw your answer looks helpful sir

    – hikki
    Jun 9 '14 at 6:51













  • @setsuna I have edited the answer to address your comment.

    – VonC
    Jun 9 '14 at 6:53











  • Only, the full syntax worked in my case.

    – Aziz Alto
    Dec 9 '16 at 3:27






  • 2





    For me, I just needed to run "git commit". :(

    – Tyler
    Jan 28 '17 at 21:00








  • 1





    Really super.. below commands worked for me... git reset --mixed origin/master git add . git commit -m "This is a new commit for what I originally planned to be amended" git push origin master Thank you @VonC

    – Hari Narayanan
    Dec 5 '17 at 5:28





















51














Did anyone try:



git push -f origin master


That should solve the problem.




EDIT: Based on @Mehdi ‘s comment below I need to clarify something about —force pushing. The git command above works safely only for the first commit. If there were already commits, pull requests or branches in previous, this resets all of it and set it from zero. If so, please refer @VonC ‘s detailed answer for better solution.







share|improve this answer





















  • 17





    Works but bad, please don't use it unless you know what you're doing. (probably you don't know what you're doing if you're looking in S.O)

    – Mehdi
    Jan 19 '18 at 9:42











  • Thanks.........!

    – Legends
    Jun 18 '18 at 13:10











  • Works for me too, thx!

    – Max
    Nov 14 '18 at 13:33






  • 1





    If you're going to try -f/--force it's always safer to use --force-with-lease instead, which will abort if there are downstream changes that would get clobbered by the push. --force-with-lease is required for lots of everyday rebasing situations, but --force should almost never be needed.

    – Joshua Goldberg
    Jan 23 at 19:13



















28














If you just used git init and have added your files with git add . or something similar and have added your remote branch it might be that you just haven't committed (git commit -m 'commit message') anything locally to push to the remote... I just had this error and that was my issue.






share|improve this answer
























  • just ran into this. Commit command didn't work during the git add. good call. Thanks

    – jgritten
    Aug 2 '18 at 2:44



















16














I had same problem. I was getting this problem because i had not made any commit not even initial commit and still i was trying to push.



Once i did git commit -m "your msg" and then everything worked fine.






share|improve this answer



















  • 4





    That doesn't make much sense. The original question is about the local git being behind. In no way "being behind" can be resolved my making a local commit!

    – GhostCat
    Jan 4 '17 at 13:19











  • Oh I also forget to commit :p

    – Shams Nahid
    Jun 16 '17 at 1:51











  • This is also possible it won't allow you to push with an empty commit

    – mboy
    Jun 22 '17 at 8:11











  • An initial commit fixed it.

    – Amit Bhagat
    Aug 7 '17 at 9:22











  • In my case, I had cherry-picked something onto my new branch and then tried to push, but got the error described in the new question; I needed to also add an "original" commit to the branch before I was able to push successfully.

    – Jon Schneider
    Oct 29 '18 at 21:49



















11














I find the solution to this problem in github help.



You can see it from:Dealing with non-fast-forward errors



It says:



You can fix this by fetching and merging the changes made on the remote branch with the changes that you have made locally:



$ git fetch origin
# Fetches updates made to an online repository
$ git merge origin branch
# Merges updates made online with your local work


Or, you can simply use git pull to perform both commands at once:



$ git pull origin branch
# Grabs online updates and merges them with your local work





share|improve this answer



















  • 3





    What if it says 'Already up to date'?

    – rubyandcoffee
    Jun 6 '17 at 23:25











  • This is the normal process whenever things are working as expected. It doesn't help anything when git thinks it is already up to date as @rubyandcoffee asked.

    – Tim
    Dec 22 '17 at 16:51



















6














Rename your branch and then push, e.g.:



git branch -m new-name
git push -u new-name


This worked for me.






share|improve this answer

































    4














    If you are using gerrit, this could be caused by an inappropriate Change-id in the commit. Try deleting the Change-Id and see what happens.






    share|improve this answer































      4














      Not commiting initial changes before pushing also causes the problem






      share|improve this answer































        3














        Remember to commit your changes before pushing to Github repo. This might fix your problem.






        share|improve this answer































          3














          before push you have to add and commit the changes or do git push -f origin master






          share|improve this answer

































            3














            1)git init



            2)git remote add origin https://gitlab.com/crew-chief-systems/bot



            3)git remote -v (for checking current repository)



            4)git add -A(add all files)



            5)git commit -m 'Added my project'



            6)git pull --rebase origin master



            7) git push origin master






            share|improve this answer
























            • before pushing the code you need to pull from repository

              – James Siva
              Sep 11 '18 at 4:27











            • you can simply write like git pull --rebase origin master

              – James Siva
              Sep 11 '18 at 4:27





















            1














            Not sure if this applies, but the fix for me was to commit something locally after git init. Then I pushed to remote using --set-upstream ...






            share|improve this answer































              0














              Well if none of the above answers are working and if you have messed up something with ssh-add lately. Try



              ssh-add -D





              share|improve this answer































                0














                In my case, this error happened because there was some maintenance happening on our version of GitLab.






                share|improve this answer































                  0














                  You can also fix it by editing the git config file of your project:



                  Where is it?



                  .git/config



                  Add the following lines at the end if they are not.



                  [branch "master"]
                  remote = origin
                  merge = refs/heads/master



                  This solved my problem






                  share|improve this answer































                    0














                    In my case closing of editor (visual studio code) solved a problem.






                    share|improve this answer































                      0














                      git error: failed to push some refs to also comes when the local repository name does match with the corresponding remote repository name. Make sure you are working on the correct pair of repository before you Pull changes to remote repository. In case you spell incorrectly and you want to remove the local repository use following steps



                      Remove the local repo from windows
                      1. del /F /S /Q /A .git
                      2. rmdir .git
                      3. Correct the local folder name(XXXX02->XXXX20) or if it is a newly created repo delete it and recreate the repo (XXXX02 Repo name changed to XXXX20).
                      4. git init
                      5. Remap with remote repo if it is not mapped.
                      6. git remote add origin https://github.com//XXXX20.git
                      7. git push -u origin master






                      share|improve this answer































                        0














                        Creating a new branch solved for me:



                        git checkout -b <nameOfNewBranch>


                        As expected no need to merge since previous branch was fully contained in the new one.






                        share|improve this answer































                          0














                          I faced with a similar problem, and I have tried the accepted answer. The result is a little different.



                          During my editing of the local repository, I modified the readme.md file in the GitHub webpage. As a result, when I try the command git pull --rebase origin master, the command line will remind me that




                          error: cannot pull with rebase: You have unstaged changes.

                          error: please commit or stash them.




                          So, I need to first execute the command git stash to store all modified files and then follow the accepted answer. After that, the locally committed files have been pushed to the Github repository. Finally, I execute the git stash pop to recover those files with unstaged changes.



                          In summary, the command sequence for me is



                          git stash
                          git pull --rebase origin master
                          git push origin master
                          git stash pop


                          As I currently cannot comment under the accepted answer, I added an answer to this question.






                          share|improve this answer



















                          • 1





                            You don't need all that: a simple git pull is enough. That is... with the right config: stackoverflow.com/a/30209750/6309

                            – VonC
                            Dec 27 '18 at 12:51











                          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%2f24114676%2fgit-error-failed-to-push-some-refs-to%23new-answer', 'question_page');
                          }
                          );

                          Post as a guest















                          Required, but never shown

























                          19 Answers
                          19






                          active

                          oldest

                          votes








                          19 Answers
                          19






                          active

                          oldest

                          votes









                          active

                          oldest

                          votes






                          active

                          oldest

                          votes









                          358














                          If the GitHub repo has seen new commits pushed to it, while you were working locally, I would advise using:



                          git pull --rebase
                          git push


                          The full syntax is:



                          git pull --rebase origin master
                          git push origin master


                          That way, you would replay (the --rebase part) your local commits on top of the newly updated origin/master (or origin/yourBranch: git pull origin yourBranch).



                          See a more complete example in the chapter 6 Pull with rebase of the Git Pocket Book.



                          I would recommend a:



                          git push -u origin master


                          That would establish a tracking relationship between your local master branch and its upstream branch.

                          After that, any future push for that branch can be done with a simple:



                          git push


                          See "Why do I need to explicitly push a new branch?".





                          Since the OP already reset and redone its commit on top of origin/master:



                          git reset --mixed origin/master
                          git add .
                          git commit -m "This is a new commit for what I originally planned to be amended"
                          git push origin master


                          There is no need to pull --rebase.



                          Note: git reset --mixed origin/master can also be written git reset origin/master, since the --mixed option is the default one when using git reset.






                          share|improve this answer


























                          • is it OK to execute your suggested git pull --rebase...? coz I already done > git reset --mixed origin/master > git add . > git commit -m "This is a new commit for what I originally planned to be an amendmend" > git push origin master suggested here stackoverflow.com/questions/18588974/… btw your answer looks helpful sir

                            – hikki
                            Jun 9 '14 at 6:51













                          • @setsuna I have edited the answer to address your comment.

                            – VonC
                            Jun 9 '14 at 6:53











                          • Only, the full syntax worked in my case.

                            – Aziz Alto
                            Dec 9 '16 at 3:27






                          • 2





                            For me, I just needed to run "git commit". :(

                            – Tyler
                            Jan 28 '17 at 21:00








                          • 1





                            Really super.. below commands worked for me... git reset --mixed origin/master git add . git commit -m "This is a new commit for what I originally planned to be amended" git push origin master Thank you @VonC

                            – Hari Narayanan
                            Dec 5 '17 at 5:28


















                          358














                          If the GitHub repo has seen new commits pushed to it, while you were working locally, I would advise using:



                          git pull --rebase
                          git push


                          The full syntax is:



                          git pull --rebase origin master
                          git push origin master


                          That way, you would replay (the --rebase part) your local commits on top of the newly updated origin/master (or origin/yourBranch: git pull origin yourBranch).



                          See a more complete example in the chapter 6 Pull with rebase of the Git Pocket Book.



                          I would recommend a:



                          git push -u origin master


                          That would establish a tracking relationship between your local master branch and its upstream branch.

                          After that, any future push for that branch can be done with a simple:



                          git push


                          See "Why do I need to explicitly push a new branch?".





                          Since the OP already reset and redone its commit on top of origin/master:



                          git reset --mixed origin/master
                          git add .
                          git commit -m "This is a new commit for what I originally planned to be amended"
                          git push origin master


                          There is no need to pull --rebase.



                          Note: git reset --mixed origin/master can also be written git reset origin/master, since the --mixed option is the default one when using git reset.






                          share|improve this answer


























                          • is it OK to execute your suggested git pull --rebase...? coz I already done > git reset --mixed origin/master > git add . > git commit -m "This is a new commit for what I originally planned to be an amendmend" > git push origin master suggested here stackoverflow.com/questions/18588974/… btw your answer looks helpful sir

                            – hikki
                            Jun 9 '14 at 6:51













                          • @setsuna I have edited the answer to address your comment.

                            – VonC
                            Jun 9 '14 at 6:53











                          • Only, the full syntax worked in my case.

                            – Aziz Alto
                            Dec 9 '16 at 3:27






                          • 2





                            For me, I just needed to run "git commit". :(

                            – Tyler
                            Jan 28 '17 at 21:00








                          • 1





                            Really super.. below commands worked for me... git reset --mixed origin/master git add . git commit -m "This is a new commit for what I originally planned to be amended" git push origin master Thank you @VonC

                            – Hari Narayanan
                            Dec 5 '17 at 5:28
















                          358












                          358








                          358







                          If the GitHub repo has seen new commits pushed to it, while you were working locally, I would advise using:



                          git pull --rebase
                          git push


                          The full syntax is:



                          git pull --rebase origin master
                          git push origin master


                          That way, you would replay (the --rebase part) your local commits on top of the newly updated origin/master (or origin/yourBranch: git pull origin yourBranch).



                          See a more complete example in the chapter 6 Pull with rebase of the Git Pocket Book.



                          I would recommend a:



                          git push -u origin master


                          That would establish a tracking relationship between your local master branch and its upstream branch.

                          After that, any future push for that branch can be done with a simple:



                          git push


                          See "Why do I need to explicitly push a new branch?".





                          Since the OP already reset and redone its commit on top of origin/master:



                          git reset --mixed origin/master
                          git add .
                          git commit -m "This is a new commit for what I originally planned to be amended"
                          git push origin master


                          There is no need to pull --rebase.



                          Note: git reset --mixed origin/master can also be written git reset origin/master, since the --mixed option is the default one when using git reset.






                          share|improve this answer















                          If the GitHub repo has seen new commits pushed to it, while you were working locally, I would advise using:



                          git pull --rebase
                          git push


                          The full syntax is:



                          git pull --rebase origin master
                          git push origin master


                          That way, you would replay (the --rebase part) your local commits on top of the newly updated origin/master (or origin/yourBranch: git pull origin yourBranch).



                          See a more complete example in the chapter 6 Pull with rebase of the Git Pocket Book.



                          I would recommend a:



                          git push -u origin master


                          That would establish a tracking relationship between your local master branch and its upstream branch.

                          After that, any future push for that branch can be done with a simple:



                          git push


                          See "Why do I need to explicitly push a new branch?".





                          Since the OP already reset and redone its commit on top of origin/master:



                          git reset --mixed origin/master
                          git add .
                          git commit -m "This is a new commit for what I originally planned to be amended"
                          git push origin master


                          There is no need to pull --rebase.



                          Note: git reset --mixed origin/master can also be written git reset origin/master, since the --mixed option is the default one when using git reset.







                          share|improve this answer














                          share|improve this answer



                          share|improve this answer








                          edited Mar 3 '18 at 14:54









                          Brad Solomon

                          14.1k83790




                          14.1k83790










                          answered Jun 9 '14 at 6:28









                          VonCVonC

                          848k29826993257




                          848k29826993257













                          • is it OK to execute your suggested git pull --rebase...? coz I already done > git reset --mixed origin/master > git add . > git commit -m "This is a new commit for what I originally planned to be an amendmend" > git push origin master suggested here stackoverflow.com/questions/18588974/… btw your answer looks helpful sir

                            – hikki
                            Jun 9 '14 at 6:51













                          • @setsuna I have edited the answer to address your comment.

                            – VonC
                            Jun 9 '14 at 6:53











                          • Only, the full syntax worked in my case.

                            – Aziz Alto
                            Dec 9 '16 at 3:27






                          • 2





                            For me, I just needed to run "git commit". :(

                            – Tyler
                            Jan 28 '17 at 21:00








                          • 1





                            Really super.. below commands worked for me... git reset --mixed origin/master git add . git commit -m "This is a new commit for what I originally planned to be amended" git push origin master Thank you @VonC

                            – Hari Narayanan
                            Dec 5 '17 at 5:28





















                          • is it OK to execute your suggested git pull --rebase...? coz I already done > git reset --mixed origin/master > git add . > git commit -m "This is a new commit for what I originally planned to be an amendmend" > git push origin master suggested here stackoverflow.com/questions/18588974/… btw your answer looks helpful sir

                            – hikki
                            Jun 9 '14 at 6:51













                          • @setsuna I have edited the answer to address your comment.

                            – VonC
                            Jun 9 '14 at 6:53











                          • Only, the full syntax worked in my case.

                            – Aziz Alto
                            Dec 9 '16 at 3:27






                          • 2





                            For me, I just needed to run "git commit". :(

                            – Tyler
                            Jan 28 '17 at 21:00








                          • 1





                            Really super.. below commands worked for me... git reset --mixed origin/master git add . git commit -m "This is a new commit for what I originally planned to be amended" git push origin master Thank you @VonC

                            – Hari Narayanan
                            Dec 5 '17 at 5:28



















                          is it OK to execute your suggested git pull --rebase...? coz I already done > git reset --mixed origin/master > git add . > git commit -m "This is a new commit for what I originally planned to be an amendmend" > git push origin master suggested here stackoverflow.com/questions/18588974/… btw your answer looks helpful sir

                          – hikki
                          Jun 9 '14 at 6:51







                          is it OK to execute your suggested git pull --rebase...? coz I already done > git reset --mixed origin/master > git add . > git commit -m "This is a new commit for what I originally planned to be an amendmend" > git push origin master suggested here stackoverflow.com/questions/18588974/… btw your answer looks helpful sir

                          – hikki
                          Jun 9 '14 at 6:51















                          @setsuna I have edited the answer to address your comment.

                          – VonC
                          Jun 9 '14 at 6:53





                          @setsuna I have edited the answer to address your comment.

                          – VonC
                          Jun 9 '14 at 6:53













                          Only, the full syntax worked in my case.

                          – Aziz Alto
                          Dec 9 '16 at 3:27





                          Only, the full syntax worked in my case.

                          – Aziz Alto
                          Dec 9 '16 at 3:27




                          2




                          2





                          For me, I just needed to run "git commit". :(

                          – Tyler
                          Jan 28 '17 at 21:00







                          For me, I just needed to run "git commit". :(

                          – Tyler
                          Jan 28 '17 at 21:00






                          1




                          1





                          Really super.. below commands worked for me... git reset --mixed origin/master git add . git commit -m "This is a new commit for what I originally planned to be amended" git push origin master Thank you @VonC

                          – Hari Narayanan
                          Dec 5 '17 at 5:28







                          Really super.. below commands worked for me... git reset --mixed origin/master git add . git commit -m "This is a new commit for what I originally planned to be amended" git push origin master Thank you @VonC

                          – Hari Narayanan
                          Dec 5 '17 at 5:28















                          51














                          Did anyone try:



                          git push -f origin master


                          That should solve the problem.




                          EDIT: Based on @Mehdi ‘s comment below I need to clarify something about —force pushing. The git command above works safely only for the first commit. If there were already commits, pull requests or branches in previous, this resets all of it and set it from zero. If so, please refer @VonC ‘s detailed answer for better solution.







                          share|improve this answer





















                          • 17





                            Works but bad, please don't use it unless you know what you're doing. (probably you don't know what you're doing if you're looking in S.O)

                            – Mehdi
                            Jan 19 '18 at 9:42











                          • Thanks.........!

                            – Legends
                            Jun 18 '18 at 13:10











                          • Works for me too, thx!

                            – Max
                            Nov 14 '18 at 13:33






                          • 1





                            If you're going to try -f/--force it's always safer to use --force-with-lease instead, which will abort if there are downstream changes that would get clobbered by the push. --force-with-lease is required for lots of everyday rebasing situations, but --force should almost never be needed.

                            – Joshua Goldberg
                            Jan 23 at 19:13
















                          51














                          Did anyone try:



                          git push -f origin master


                          That should solve the problem.




                          EDIT: Based on @Mehdi ‘s comment below I need to clarify something about —force pushing. The git command above works safely only for the first commit. If there were already commits, pull requests or branches in previous, this resets all of it and set it from zero. If so, please refer @VonC ‘s detailed answer for better solution.







                          share|improve this answer





















                          • 17





                            Works but bad, please don't use it unless you know what you're doing. (probably you don't know what you're doing if you're looking in S.O)

                            – Mehdi
                            Jan 19 '18 at 9:42











                          • Thanks.........!

                            – Legends
                            Jun 18 '18 at 13:10











                          • Works for me too, thx!

                            – Max
                            Nov 14 '18 at 13:33






                          • 1





                            If you're going to try -f/--force it's always safer to use --force-with-lease instead, which will abort if there are downstream changes that would get clobbered by the push. --force-with-lease is required for lots of everyday rebasing situations, but --force should almost never be needed.

                            – Joshua Goldberg
                            Jan 23 at 19:13














                          51












                          51








                          51







                          Did anyone try:



                          git push -f origin master


                          That should solve the problem.




                          EDIT: Based on @Mehdi ‘s comment below I need to clarify something about —force pushing. The git command above works safely only for the first commit. If there were already commits, pull requests or branches in previous, this resets all of it and set it from zero. If so, please refer @VonC ‘s detailed answer for better solution.







                          share|improve this answer















                          Did anyone try:



                          git push -f origin master


                          That should solve the problem.




                          EDIT: Based on @Mehdi ‘s comment below I need to clarify something about —force pushing. The git command above works safely only for the first commit. If there were already commits, pull requests or branches in previous, this resets all of it and set it from zero. If so, please refer @VonC ‘s detailed answer for better solution.








                          share|improve this answer














                          share|improve this answer



                          share|improve this answer








                          edited Jan 19 '18 at 17:26

























                          answered Mar 18 '17 at 13:41









                          CagCakCagCak

                          1,21611618




                          1,21611618








                          • 17





                            Works but bad, please don't use it unless you know what you're doing. (probably you don't know what you're doing if you're looking in S.O)

                            – Mehdi
                            Jan 19 '18 at 9:42











                          • Thanks.........!

                            – Legends
                            Jun 18 '18 at 13:10











                          • Works for me too, thx!

                            – Max
                            Nov 14 '18 at 13:33






                          • 1





                            If you're going to try -f/--force it's always safer to use --force-with-lease instead, which will abort if there are downstream changes that would get clobbered by the push. --force-with-lease is required for lots of everyday rebasing situations, but --force should almost never be needed.

                            – Joshua Goldberg
                            Jan 23 at 19:13














                          • 17





                            Works but bad, please don't use it unless you know what you're doing. (probably you don't know what you're doing if you're looking in S.O)

                            – Mehdi
                            Jan 19 '18 at 9:42











                          • Thanks.........!

                            – Legends
                            Jun 18 '18 at 13:10











                          • Works for me too, thx!

                            – Max
                            Nov 14 '18 at 13:33






                          • 1





                            If you're going to try -f/--force it's always safer to use --force-with-lease instead, which will abort if there are downstream changes that would get clobbered by the push. --force-with-lease is required for lots of everyday rebasing situations, but --force should almost never be needed.

                            – Joshua Goldberg
                            Jan 23 at 19:13








                          17




                          17





                          Works but bad, please don't use it unless you know what you're doing. (probably you don't know what you're doing if you're looking in S.O)

                          – Mehdi
                          Jan 19 '18 at 9:42





                          Works but bad, please don't use it unless you know what you're doing. (probably you don't know what you're doing if you're looking in S.O)

                          – Mehdi
                          Jan 19 '18 at 9:42













                          Thanks.........!

                          – Legends
                          Jun 18 '18 at 13:10





                          Thanks.........!

                          – Legends
                          Jun 18 '18 at 13:10













                          Works for me too, thx!

                          – Max
                          Nov 14 '18 at 13:33





                          Works for me too, thx!

                          – Max
                          Nov 14 '18 at 13:33




                          1




                          1





                          If you're going to try -f/--force it's always safer to use --force-with-lease instead, which will abort if there are downstream changes that would get clobbered by the push. --force-with-lease is required for lots of everyday rebasing situations, but --force should almost never be needed.

                          – Joshua Goldberg
                          Jan 23 at 19:13





                          If you're going to try -f/--force it's always safer to use --force-with-lease instead, which will abort if there are downstream changes that would get clobbered by the push. --force-with-lease is required for lots of everyday rebasing situations, but --force should almost never be needed.

                          – Joshua Goldberg
                          Jan 23 at 19:13











                          28














                          If you just used git init and have added your files with git add . or something similar and have added your remote branch it might be that you just haven't committed (git commit -m 'commit message') anything locally to push to the remote... I just had this error and that was my issue.






                          share|improve this answer
























                          • just ran into this. Commit command didn't work during the git add. good call. Thanks

                            – jgritten
                            Aug 2 '18 at 2:44
















                          28














                          If you just used git init and have added your files with git add . or something similar and have added your remote branch it might be that you just haven't committed (git commit -m 'commit message') anything locally to push to the remote... I just had this error and that was my issue.






                          share|improve this answer
























                          • just ran into this. Commit command didn't work during the git add. good call. Thanks

                            – jgritten
                            Aug 2 '18 at 2:44














                          28












                          28








                          28







                          If you just used git init and have added your files with git add . or something similar and have added your remote branch it might be that you just haven't committed (git commit -m 'commit message') anything locally to push to the remote... I just had this error and that was my issue.






                          share|improve this answer













                          If you just used git init and have added your files with git add . or something similar and have added your remote branch it might be that you just haven't committed (git commit -m 'commit message') anything locally to push to the remote... I just had this error and that was my issue.







                          share|improve this answer












                          share|improve this answer



                          share|improve this answer










                          answered May 22 '15 at 18:57









                          ironcladmvtmironcladmvtm

                          41944




                          41944













                          • just ran into this. Commit command didn't work during the git add. good call. Thanks

                            – jgritten
                            Aug 2 '18 at 2:44



















                          • just ran into this. Commit command didn't work during the git add. good call. Thanks

                            – jgritten
                            Aug 2 '18 at 2:44

















                          just ran into this. Commit command didn't work during the git add. good call. Thanks

                          – jgritten
                          Aug 2 '18 at 2:44





                          just ran into this. Commit command didn't work during the git add. good call. Thanks

                          – jgritten
                          Aug 2 '18 at 2:44











                          16














                          I had same problem. I was getting this problem because i had not made any commit not even initial commit and still i was trying to push.



                          Once i did git commit -m "your msg" and then everything worked fine.






                          share|improve this answer



















                          • 4





                            That doesn't make much sense. The original question is about the local git being behind. In no way "being behind" can be resolved my making a local commit!

                            – GhostCat
                            Jan 4 '17 at 13:19











                          • Oh I also forget to commit :p

                            – Shams Nahid
                            Jun 16 '17 at 1:51











                          • This is also possible it won't allow you to push with an empty commit

                            – mboy
                            Jun 22 '17 at 8:11











                          • An initial commit fixed it.

                            – Amit Bhagat
                            Aug 7 '17 at 9:22











                          • In my case, I had cherry-picked something onto my new branch and then tried to push, but got the error described in the new question; I needed to also add an "original" commit to the branch before I was able to push successfully.

                            – Jon Schneider
                            Oct 29 '18 at 21:49
















                          16














                          I had same problem. I was getting this problem because i had not made any commit not even initial commit and still i was trying to push.



                          Once i did git commit -m "your msg" and then everything worked fine.






                          share|improve this answer



















                          • 4





                            That doesn't make much sense. The original question is about the local git being behind. In no way "being behind" can be resolved my making a local commit!

                            – GhostCat
                            Jan 4 '17 at 13:19











                          • Oh I also forget to commit :p

                            – Shams Nahid
                            Jun 16 '17 at 1:51











                          • This is also possible it won't allow you to push with an empty commit

                            – mboy
                            Jun 22 '17 at 8:11











                          • An initial commit fixed it.

                            – Amit Bhagat
                            Aug 7 '17 at 9:22











                          • In my case, I had cherry-picked something onto my new branch and then tried to push, but got the error described in the new question; I needed to also add an "original" commit to the branch before I was able to push successfully.

                            – Jon Schneider
                            Oct 29 '18 at 21:49














                          16












                          16








                          16







                          I had same problem. I was getting this problem because i had not made any commit not even initial commit and still i was trying to push.



                          Once i did git commit -m "your msg" and then everything worked fine.






                          share|improve this answer













                          I had same problem. I was getting this problem because i had not made any commit not even initial commit and still i was trying to push.



                          Once i did git commit -m "your msg" and then everything worked fine.







                          share|improve this answer












                          share|improve this answer



                          share|improve this answer










                          answered Jan 4 '17 at 13:16









                          ppmakeitcountppmakeitcount

                          17616




                          17616








                          • 4





                            That doesn't make much sense. The original question is about the local git being behind. In no way "being behind" can be resolved my making a local commit!

                            – GhostCat
                            Jan 4 '17 at 13:19











                          • Oh I also forget to commit :p

                            – Shams Nahid
                            Jun 16 '17 at 1:51











                          • This is also possible it won't allow you to push with an empty commit

                            – mboy
                            Jun 22 '17 at 8:11











                          • An initial commit fixed it.

                            – Amit Bhagat
                            Aug 7 '17 at 9:22











                          • In my case, I had cherry-picked something onto my new branch and then tried to push, but got the error described in the new question; I needed to also add an "original" commit to the branch before I was able to push successfully.

                            – Jon Schneider
                            Oct 29 '18 at 21:49














                          • 4





                            That doesn't make much sense. The original question is about the local git being behind. In no way "being behind" can be resolved my making a local commit!

                            – GhostCat
                            Jan 4 '17 at 13:19











                          • Oh I also forget to commit :p

                            – Shams Nahid
                            Jun 16 '17 at 1:51











                          • This is also possible it won't allow you to push with an empty commit

                            – mboy
                            Jun 22 '17 at 8:11











                          • An initial commit fixed it.

                            – Amit Bhagat
                            Aug 7 '17 at 9:22











                          • In my case, I had cherry-picked something onto my new branch and then tried to push, but got the error described in the new question; I needed to also add an "original" commit to the branch before I was able to push successfully.

                            – Jon Schneider
                            Oct 29 '18 at 21:49








                          4




                          4





                          That doesn't make much sense. The original question is about the local git being behind. In no way "being behind" can be resolved my making a local commit!

                          – GhostCat
                          Jan 4 '17 at 13:19





                          That doesn't make much sense. The original question is about the local git being behind. In no way "being behind" can be resolved my making a local commit!

                          – GhostCat
                          Jan 4 '17 at 13:19













                          Oh I also forget to commit :p

                          – Shams Nahid
                          Jun 16 '17 at 1:51





                          Oh I also forget to commit :p

                          – Shams Nahid
                          Jun 16 '17 at 1:51













                          This is also possible it won't allow you to push with an empty commit

                          – mboy
                          Jun 22 '17 at 8:11





                          This is also possible it won't allow you to push with an empty commit

                          – mboy
                          Jun 22 '17 at 8:11













                          An initial commit fixed it.

                          – Amit Bhagat
                          Aug 7 '17 at 9:22





                          An initial commit fixed it.

                          – Amit Bhagat
                          Aug 7 '17 at 9:22













                          In my case, I had cherry-picked something onto my new branch and then tried to push, but got the error described in the new question; I needed to also add an "original" commit to the branch before I was able to push successfully.

                          – Jon Schneider
                          Oct 29 '18 at 21:49





                          In my case, I had cherry-picked something onto my new branch and then tried to push, but got the error described in the new question; I needed to also add an "original" commit to the branch before I was able to push successfully.

                          – Jon Schneider
                          Oct 29 '18 at 21:49











                          11














                          I find the solution to this problem in github help.



                          You can see it from:Dealing with non-fast-forward errors



                          It says:



                          You can fix this by fetching and merging the changes made on the remote branch with the changes that you have made locally:



                          $ git fetch origin
                          # Fetches updates made to an online repository
                          $ git merge origin branch
                          # Merges updates made online with your local work


                          Or, you can simply use git pull to perform both commands at once:



                          $ git pull origin branch
                          # Grabs online updates and merges them with your local work





                          share|improve this answer



















                          • 3





                            What if it says 'Already up to date'?

                            – rubyandcoffee
                            Jun 6 '17 at 23:25











                          • This is the normal process whenever things are working as expected. It doesn't help anything when git thinks it is already up to date as @rubyandcoffee asked.

                            – Tim
                            Dec 22 '17 at 16:51
















                          11














                          I find the solution to this problem in github help.



                          You can see it from:Dealing with non-fast-forward errors



                          It says:



                          You can fix this by fetching and merging the changes made on the remote branch with the changes that you have made locally:



                          $ git fetch origin
                          # Fetches updates made to an online repository
                          $ git merge origin branch
                          # Merges updates made online with your local work


                          Or, you can simply use git pull to perform both commands at once:



                          $ git pull origin branch
                          # Grabs online updates and merges them with your local work





                          share|improve this answer



















                          • 3





                            What if it says 'Already up to date'?

                            – rubyandcoffee
                            Jun 6 '17 at 23:25











                          • This is the normal process whenever things are working as expected. It doesn't help anything when git thinks it is already up to date as @rubyandcoffee asked.

                            – Tim
                            Dec 22 '17 at 16:51














                          11












                          11








                          11







                          I find the solution to this problem in github help.



                          You can see it from:Dealing with non-fast-forward errors



                          It says:



                          You can fix this by fetching and merging the changes made on the remote branch with the changes that you have made locally:



                          $ git fetch origin
                          # Fetches updates made to an online repository
                          $ git merge origin branch
                          # Merges updates made online with your local work


                          Or, you can simply use git pull to perform both commands at once:



                          $ git pull origin branch
                          # Grabs online updates and merges them with your local work





                          share|improve this answer













                          I find the solution to this problem in github help.



                          You can see it from:Dealing with non-fast-forward errors



                          It says:



                          You can fix this by fetching and merging the changes made on the remote branch with the changes that you have made locally:



                          $ git fetch origin
                          # Fetches updates made to an online repository
                          $ git merge origin branch
                          # Merges updates made online with your local work


                          Or, you can simply use git pull to perform both commands at once:



                          $ git pull origin branch
                          # Grabs online updates and merges them with your local work






                          share|improve this answer












                          share|improve this answer



                          share|improve this answer










                          answered Nov 21 '14 at 6:28









                          SealterSealter

                          16426




                          16426








                          • 3





                            What if it says 'Already up to date'?

                            – rubyandcoffee
                            Jun 6 '17 at 23:25











                          • This is the normal process whenever things are working as expected. It doesn't help anything when git thinks it is already up to date as @rubyandcoffee asked.

                            – Tim
                            Dec 22 '17 at 16:51














                          • 3





                            What if it says 'Already up to date'?

                            – rubyandcoffee
                            Jun 6 '17 at 23:25











                          • This is the normal process whenever things are working as expected. It doesn't help anything when git thinks it is already up to date as @rubyandcoffee asked.

                            – Tim
                            Dec 22 '17 at 16:51








                          3




                          3





                          What if it says 'Already up to date'?

                          – rubyandcoffee
                          Jun 6 '17 at 23:25





                          What if it says 'Already up to date'?

                          – rubyandcoffee
                          Jun 6 '17 at 23:25













                          This is the normal process whenever things are working as expected. It doesn't help anything when git thinks it is already up to date as @rubyandcoffee asked.

                          – Tim
                          Dec 22 '17 at 16:51





                          This is the normal process whenever things are working as expected. It doesn't help anything when git thinks it is already up to date as @rubyandcoffee asked.

                          – Tim
                          Dec 22 '17 at 16:51











                          6














                          Rename your branch and then push, e.g.:



                          git branch -m new-name
                          git push -u new-name


                          This worked for me.






                          share|improve this answer






























                            6














                            Rename your branch and then push, e.g.:



                            git branch -m new-name
                            git push -u new-name


                            This worked for me.






                            share|improve this answer




























                              6












                              6








                              6







                              Rename your branch and then push, e.g.:



                              git branch -m new-name
                              git push -u new-name


                              This worked for me.






                              share|improve this answer















                              Rename your branch and then push, e.g.:



                              git branch -m new-name
                              git push -u new-name


                              This worked for me.







                              share|improve this answer














                              share|improve this answer



                              share|improve this answer








                              edited Feb 1 '18 at 5:53









                              clemens

                              10.5k102643




                              10.5k102643










                              answered Feb 1 '18 at 5:47









                              p8ulp8ul

                              14416




                              14416























                                  4














                                  If you are using gerrit, this could be caused by an inappropriate Change-id in the commit. Try deleting the Change-Id and see what happens.






                                  share|improve this answer




























                                    4














                                    If you are using gerrit, this could be caused by an inappropriate Change-id in the commit. Try deleting the Change-Id and see what happens.






                                    share|improve this answer


























                                      4












                                      4








                                      4







                                      If you are using gerrit, this could be caused by an inappropriate Change-id in the commit. Try deleting the Change-Id and see what happens.






                                      share|improve this answer













                                      If you are using gerrit, this could be caused by an inappropriate Change-id in the commit. Try deleting the Change-Id and see what happens.







                                      share|improve this answer












                                      share|improve this answer



                                      share|improve this answer










                                      answered Jul 5 '16 at 9:22









                                      Jim SimeJim Sime

                                      11111




                                      11111























                                          4














                                          Not commiting initial changes before pushing also causes the problem






                                          share|improve this answer




























                                            4














                                            Not commiting initial changes before pushing also causes the problem






                                            share|improve this answer


























                                              4












                                              4








                                              4







                                              Not commiting initial changes before pushing also causes the problem






                                              share|improve this answer













                                              Not commiting initial changes before pushing also causes the problem







                                              share|improve this answer












                                              share|improve this answer



                                              share|improve this answer










                                              answered May 6 '18 at 7:26









                                              ClawClaw

                                              412




                                              412























                                                  3














                                                  Remember to commit your changes before pushing to Github repo. This might fix your problem.






                                                  share|improve this answer




























                                                    3














                                                    Remember to commit your changes before pushing to Github repo. This might fix your problem.






                                                    share|improve this answer


























                                                      3












                                                      3








                                                      3







                                                      Remember to commit your changes before pushing to Github repo. This might fix your problem.






                                                      share|improve this answer













                                                      Remember to commit your changes before pushing to Github repo. This might fix your problem.







                                                      share|improve this answer












                                                      share|improve this answer



                                                      share|improve this answer










                                                      answered Dec 13 '16 at 18:13









                                                      Alf MohAlf Moh

                                                      3,73532335




                                                      3,73532335























                                                          3














                                                          before push you have to add and commit the changes or do git push -f origin master






                                                          share|improve this answer






























                                                            3














                                                            before push you have to add and commit the changes or do git push -f origin master






                                                            share|improve this answer




























                                                              3












                                                              3








                                                              3







                                                              before push you have to add and commit the changes or do git push -f origin master






                                                              share|improve this answer















                                                              before push you have to add and commit the changes or do git push -f origin master







                                                              share|improve this answer














                                                              share|improve this answer



                                                              share|improve this answer








                                                              edited Dec 14 '17 at 15:15









                                                              Muhammad

                                                              1,93642850




                                                              1,93642850










                                                              answered Dec 14 '17 at 14:05









                                                              Kinnera ReddyKinnera Reddy

                                                              562




                                                              562























                                                                  3














                                                                  1)git init



                                                                  2)git remote add origin https://gitlab.com/crew-chief-systems/bot



                                                                  3)git remote -v (for checking current repository)



                                                                  4)git add -A(add all files)



                                                                  5)git commit -m 'Added my project'



                                                                  6)git pull --rebase origin master



                                                                  7) git push origin master






                                                                  share|improve this answer
























                                                                  • before pushing the code you need to pull from repository

                                                                    – James Siva
                                                                    Sep 11 '18 at 4:27











                                                                  • you can simply write like git pull --rebase origin master

                                                                    – James Siva
                                                                    Sep 11 '18 at 4:27


















                                                                  3














                                                                  1)git init



                                                                  2)git remote add origin https://gitlab.com/crew-chief-systems/bot



                                                                  3)git remote -v (for checking current repository)



                                                                  4)git add -A(add all files)



                                                                  5)git commit -m 'Added my project'



                                                                  6)git pull --rebase origin master



                                                                  7) git push origin master






                                                                  share|improve this answer
























                                                                  • before pushing the code you need to pull from repository

                                                                    – James Siva
                                                                    Sep 11 '18 at 4:27











                                                                  • you can simply write like git pull --rebase origin master

                                                                    – James Siva
                                                                    Sep 11 '18 at 4:27
















                                                                  3












                                                                  3








                                                                  3







                                                                  1)git init



                                                                  2)git remote add origin https://gitlab.com/crew-chief-systems/bot



                                                                  3)git remote -v (for checking current repository)



                                                                  4)git add -A(add all files)



                                                                  5)git commit -m 'Added my project'



                                                                  6)git pull --rebase origin master



                                                                  7) git push origin master






                                                                  share|improve this answer













                                                                  1)git init



                                                                  2)git remote add origin https://gitlab.com/crew-chief-systems/bot



                                                                  3)git remote -v (for checking current repository)



                                                                  4)git add -A(add all files)



                                                                  5)git commit -m 'Added my project'



                                                                  6)git pull --rebase origin master



                                                                  7) git push origin master







                                                                  share|improve this answer












                                                                  share|improve this answer



                                                                  share|improve this answer










                                                                  answered Sep 11 '18 at 4:25









                                                                  James SivaJames Siva

                                                                  656




                                                                  656













                                                                  • before pushing the code you need to pull from repository

                                                                    – James Siva
                                                                    Sep 11 '18 at 4:27











                                                                  • you can simply write like git pull --rebase origin master

                                                                    – James Siva
                                                                    Sep 11 '18 at 4:27





















                                                                  • before pushing the code you need to pull from repository

                                                                    – James Siva
                                                                    Sep 11 '18 at 4:27











                                                                  • you can simply write like git pull --rebase origin master

                                                                    – James Siva
                                                                    Sep 11 '18 at 4:27



















                                                                  before pushing the code you need to pull from repository

                                                                  – James Siva
                                                                  Sep 11 '18 at 4:27





                                                                  before pushing the code you need to pull from repository

                                                                  – James Siva
                                                                  Sep 11 '18 at 4:27













                                                                  you can simply write like git pull --rebase origin master

                                                                  – James Siva
                                                                  Sep 11 '18 at 4:27







                                                                  you can simply write like git pull --rebase origin master

                                                                  – James Siva
                                                                  Sep 11 '18 at 4:27













                                                                  1














                                                                  Not sure if this applies, but the fix for me was to commit something locally after git init. Then I pushed to remote using --set-upstream ...






                                                                  share|improve this answer




























                                                                    1














                                                                    Not sure if this applies, but the fix for me was to commit something locally after git init. Then I pushed to remote using --set-upstream ...






                                                                    share|improve this answer


























                                                                      1












                                                                      1








                                                                      1







                                                                      Not sure if this applies, but the fix for me was to commit something locally after git init. Then I pushed to remote using --set-upstream ...






                                                                      share|improve this answer













                                                                      Not sure if this applies, but the fix for me was to commit something locally after git init. Then I pushed to remote using --set-upstream ...







                                                                      share|improve this answer












                                                                      share|improve this answer



                                                                      share|improve this answer










                                                                      answered Mar 17 '18 at 17:33









                                                                      user1889992user1889992

                                                                      13017




                                                                      13017























                                                                          0














                                                                          Well if none of the above answers are working and if you have messed up something with ssh-add lately. Try



                                                                          ssh-add -D





                                                                          share|improve this answer




























                                                                            0














                                                                            Well if none of the above answers are working and if you have messed up something with ssh-add lately. Try



                                                                            ssh-add -D





                                                                            share|improve this answer


























                                                                              0












                                                                              0








                                                                              0







                                                                              Well if none of the above answers are working and if you have messed up something with ssh-add lately. Try



                                                                              ssh-add -D





                                                                              share|improve this answer













                                                                              Well if none of the above answers are working and if you have messed up something with ssh-add lately. Try



                                                                              ssh-add -D






                                                                              share|improve this answer












                                                                              share|improve this answer



                                                                              share|improve this answer










                                                                              answered Apr 3 '17 at 17:25









                                                                              AbhisekAbhisek

                                                                              4711614




                                                                              4711614























                                                                                  0














                                                                                  In my case, this error happened because there was some maintenance happening on our version of GitLab.






                                                                                  share|improve this answer




























                                                                                    0














                                                                                    In my case, this error happened because there was some maintenance happening on our version of GitLab.






                                                                                    share|improve this answer


























                                                                                      0












                                                                                      0








                                                                                      0







                                                                                      In my case, this error happened because there was some maintenance happening on our version of GitLab.






                                                                                      share|improve this answer













                                                                                      In my case, this error happened because there was some maintenance happening on our version of GitLab.







                                                                                      share|improve this answer












                                                                                      share|improve this answer



                                                                                      share|improve this answer










                                                                                      answered Jun 21 '17 at 16:47









                                                                                      GreenGiantGreenGiant

                                                                                      2,85413359




                                                                                      2,85413359























                                                                                          0














                                                                                          You can also fix it by editing the git config file of your project:



                                                                                          Where is it?



                                                                                          .git/config



                                                                                          Add the following lines at the end if they are not.



                                                                                          [branch "master"]
                                                                                          remote = origin
                                                                                          merge = refs/heads/master



                                                                                          This solved my problem






                                                                                          share|improve this answer




























                                                                                            0














                                                                                            You can also fix it by editing the git config file of your project:



                                                                                            Where is it?



                                                                                            .git/config



                                                                                            Add the following lines at the end if they are not.



                                                                                            [branch "master"]
                                                                                            remote = origin
                                                                                            merge = refs/heads/master



                                                                                            This solved my problem






                                                                                            share|improve this answer


























                                                                                              0












                                                                                              0








                                                                                              0







                                                                                              You can also fix it by editing the git config file of your project:



                                                                                              Where is it?



                                                                                              .git/config



                                                                                              Add the following lines at the end if they are not.



                                                                                              [branch "master"]
                                                                                              remote = origin
                                                                                              merge = refs/heads/master



                                                                                              This solved my problem






                                                                                              share|improve this answer













                                                                                              You can also fix it by editing the git config file of your project:



                                                                                              Where is it?



                                                                                              .git/config



                                                                                              Add the following lines at the end if they are not.



                                                                                              [branch "master"]
                                                                                              remote = origin
                                                                                              merge = refs/heads/master



                                                                                              This solved my problem







                                                                                              share|improve this answer












                                                                                              share|improve this answer



                                                                                              share|improve this answer










                                                                                              answered Dec 23 '17 at 5:46









                                                                                              EddEdd

                                                                                              287




                                                                                              287























                                                                                                  0














                                                                                                  In my case closing of editor (visual studio code) solved a problem.






                                                                                                  share|improve this answer




























                                                                                                    0














                                                                                                    In my case closing of editor (visual studio code) solved a problem.






                                                                                                    share|improve this answer


























                                                                                                      0












                                                                                                      0








                                                                                                      0







                                                                                                      In my case closing of editor (visual studio code) solved a problem.






                                                                                                      share|improve this answer













                                                                                                      In my case closing of editor (visual studio code) solved a problem.







                                                                                                      share|improve this answer












                                                                                                      share|improve this answer



                                                                                                      share|improve this answer










                                                                                                      answered Jan 24 '18 at 12:01









                                                                                                      Vasyl GutnykVasyl Gutnyk

                                                                                                      2,67421925




                                                                                                      2,67421925























                                                                                                          0














                                                                                                          git error: failed to push some refs to also comes when the local repository name does match with the corresponding remote repository name. Make sure you are working on the correct pair of repository before you Pull changes to remote repository. In case you spell incorrectly and you want to remove the local repository use following steps



                                                                                                          Remove the local repo from windows
                                                                                                          1. del /F /S /Q /A .git
                                                                                                          2. rmdir .git
                                                                                                          3. Correct the local folder name(XXXX02->XXXX20) or if it is a newly created repo delete it and recreate the repo (XXXX02 Repo name changed to XXXX20).
                                                                                                          4. git init
                                                                                                          5. Remap with remote repo if it is not mapped.
                                                                                                          6. git remote add origin https://github.com//XXXX20.git
                                                                                                          7. git push -u origin master






                                                                                                          share|improve this answer




























                                                                                                            0














                                                                                                            git error: failed to push some refs to also comes when the local repository name does match with the corresponding remote repository name. Make sure you are working on the correct pair of repository before you Pull changes to remote repository. In case you spell incorrectly and you want to remove the local repository use following steps



                                                                                                            Remove the local repo from windows
                                                                                                            1. del /F /S /Q /A .git
                                                                                                            2. rmdir .git
                                                                                                            3. Correct the local folder name(XXXX02->XXXX20) or if it is a newly created repo delete it and recreate the repo (XXXX02 Repo name changed to XXXX20).
                                                                                                            4. git init
                                                                                                            5. Remap with remote repo if it is not mapped.
                                                                                                            6. git remote add origin https://github.com//XXXX20.git
                                                                                                            7. git push -u origin master






                                                                                                            share|improve this answer


























                                                                                                              0












                                                                                                              0








                                                                                                              0







                                                                                                              git error: failed to push some refs to also comes when the local repository name does match with the corresponding remote repository name. Make sure you are working on the correct pair of repository before you Pull changes to remote repository. In case you spell incorrectly and you want to remove the local repository use following steps



                                                                                                              Remove the local repo from windows
                                                                                                              1. del /F /S /Q /A .git
                                                                                                              2. rmdir .git
                                                                                                              3. Correct the local folder name(XXXX02->XXXX20) or if it is a newly created repo delete it and recreate the repo (XXXX02 Repo name changed to XXXX20).
                                                                                                              4. git init
                                                                                                              5. Remap with remote repo if it is not mapped.
                                                                                                              6. git remote add origin https://github.com//XXXX20.git
                                                                                                              7. git push -u origin master






                                                                                                              share|improve this answer













                                                                                                              git error: failed to push some refs to also comes when the local repository name does match with the corresponding remote repository name. Make sure you are working on the correct pair of repository before you Pull changes to remote repository. In case you spell incorrectly and you want to remove the local repository use following steps



                                                                                                              Remove the local repo from windows
                                                                                                              1. del /F /S /Q /A .git
                                                                                                              2. rmdir .git
                                                                                                              3. Correct the local folder name(XXXX02->XXXX20) or if it is a newly created repo delete it and recreate the repo (XXXX02 Repo name changed to XXXX20).
                                                                                                              4. git init
                                                                                                              5. Remap with remote repo if it is not mapped.
                                                                                                              6. git remote add origin https://github.com//XXXX20.git
                                                                                                              7. git push -u origin master







                                                                                                              share|improve this answer












                                                                                                              share|improve this answer



                                                                                                              share|improve this answer










                                                                                                              answered Mar 16 '18 at 2:27









                                                                                                              Sunil Vishnu RaskarSunil Vishnu Raskar

                                                                                                              922




                                                                                                              922























                                                                                                                  0














                                                                                                                  Creating a new branch solved for me:



                                                                                                                  git checkout -b <nameOfNewBranch>


                                                                                                                  As expected no need to merge since previous branch was fully contained in the new one.






                                                                                                                  share|improve this answer




























                                                                                                                    0














                                                                                                                    Creating a new branch solved for me:



                                                                                                                    git checkout -b <nameOfNewBranch>


                                                                                                                    As expected no need to merge since previous branch was fully contained in the new one.






                                                                                                                    share|improve this answer


























                                                                                                                      0












                                                                                                                      0








                                                                                                                      0







                                                                                                                      Creating a new branch solved for me:



                                                                                                                      git checkout -b <nameOfNewBranch>


                                                                                                                      As expected no need to merge since previous branch was fully contained in the new one.






                                                                                                                      share|improve this answer













                                                                                                                      Creating a new branch solved for me:



                                                                                                                      git checkout -b <nameOfNewBranch>


                                                                                                                      As expected no need to merge since previous branch was fully contained in the new one.







                                                                                                                      share|improve this answer












                                                                                                                      share|improve this answer



                                                                                                                      share|improve this answer










                                                                                                                      answered Nov 15 '18 at 21:41









                                                                                                                      Santiago M. QuinteroSantiago M. Quintero

                                                                                                                      418415




                                                                                                                      418415























                                                                                                                          0














                                                                                                                          I faced with a similar problem, and I have tried the accepted answer. The result is a little different.



                                                                                                                          During my editing of the local repository, I modified the readme.md file in the GitHub webpage. As a result, when I try the command git pull --rebase origin master, the command line will remind me that




                                                                                                                          error: cannot pull with rebase: You have unstaged changes.

                                                                                                                          error: please commit or stash them.




                                                                                                                          So, I need to first execute the command git stash to store all modified files and then follow the accepted answer. After that, the locally committed files have been pushed to the Github repository. Finally, I execute the git stash pop to recover those files with unstaged changes.



                                                                                                                          In summary, the command sequence for me is



                                                                                                                          git stash
                                                                                                                          git pull --rebase origin master
                                                                                                                          git push origin master
                                                                                                                          git stash pop


                                                                                                                          As I currently cannot comment under the accepted answer, I added an answer to this question.






                                                                                                                          share|improve this answer



















                                                                                                                          • 1





                                                                                                                            You don't need all that: a simple git pull is enough. That is... with the right config: stackoverflow.com/a/30209750/6309

                                                                                                                            – VonC
                                                                                                                            Dec 27 '18 at 12:51
















                                                                                                                          0














                                                                                                                          I faced with a similar problem, and I have tried the accepted answer. The result is a little different.



                                                                                                                          During my editing of the local repository, I modified the readme.md file in the GitHub webpage. As a result, when I try the command git pull --rebase origin master, the command line will remind me that




                                                                                                                          error: cannot pull with rebase: You have unstaged changes.

                                                                                                                          error: please commit or stash them.




                                                                                                                          So, I need to first execute the command git stash to store all modified files and then follow the accepted answer. After that, the locally committed files have been pushed to the Github repository. Finally, I execute the git stash pop to recover those files with unstaged changes.



                                                                                                                          In summary, the command sequence for me is



                                                                                                                          git stash
                                                                                                                          git pull --rebase origin master
                                                                                                                          git push origin master
                                                                                                                          git stash pop


                                                                                                                          As I currently cannot comment under the accepted answer, I added an answer to this question.






                                                                                                                          share|improve this answer



















                                                                                                                          • 1





                                                                                                                            You don't need all that: a simple git pull is enough. That is... with the right config: stackoverflow.com/a/30209750/6309

                                                                                                                            – VonC
                                                                                                                            Dec 27 '18 at 12:51














                                                                                                                          0












                                                                                                                          0








                                                                                                                          0







                                                                                                                          I faced with a similar problem, and I have tried the accepted answer. The result is a little different.



                                                                                                                          During my editing of the local repository, I modified the readme.md file in the GitHub webpage. As a result, when I try the command git pull --rebase origin master, the command line will remind me that




                                                                                                                          error: cannot pull with rebase: You have unstaged changes.

                                                                                                                          error: please commit or stash them.




                                                                                                                          So, I need to first execute the command git stash to store all modified files and then follow the accepted answer. After that, the locally committed files have been pushed to the Github repository. Finally, I execute the git stash pop to recover those files with unstaged changes.



                                                                                                                          In summary, the command sequence for me is



                                                                                                                          git stash
                                                                                                                          git pull --rebase origin master
                                                                                                                          git push origin master
                                                                                                                          git stash pop


                                                                                                                          As I currently cannot comment under the accepted answer, I added an answer to this question.






                                                                                                                          share|improve this answer













                                                                                                                          I faced with a similar problem, and I have tried the accepted answer. The result is a little different.



                                                                                                                          During my editing of the local repository, I modified the readme.md file in the GitHub webpage. As a result, when I try the command git pull --rebase origin master, the command line will remind me that




                                                                                                                          error: cannot pull with rebase: You have unstaged changes.

                                                                                                                          error: please commit or stash them.




                                                                                                                          So, I need to first execute the command git stash to store all modified files and then follow the accepted answer. After that, the locally committed files have been pushed to the Github repository. Finally, I execute the git stash pop to recover those files with unstaged changes.



                                                                                                                          In summary, the command sequence for me is



                                                                                                                          git stash
                                                                                                                          git pull --rebase origin master
                                                                                                                          git push origin master
                                                                                                                          git stash pop


                                                                                                                          As I currently cannot comment under the accepted answer, I added an answer to this question.







                                                                                                                          share|improve this answer












                                                                                                                          share|improve this answer



                                                                                                                          share|improve this answer










                                                                                                                          answered Dec 27 '18 at 12:50









                                                                                                                          Gary WangGary Wang

                                                                                                                          3616




                                                                                                                          3616








                                                                                                                          • 1





                                                                                                                            You don't need all that: a simple git pull is enough. That is... with the right config: stackoverflow.com/a/30209750/6309

                                                                                                                            – VonC
                                                                                                                            Dec 27 '18 at 12:51














                                                                                                                          • 1





                                                                                                                            You don't need all that: a simple git pull is enough. That is... with the right config: stackoverflow.com/a/30209750/6309

                                                                                                                            – VonC
                                                                                                                            Dec 27 '18 at 12:51








                                                                                                                          1




                                                                                                                          1





                                                                                                                          You don't need all that: a simple git pull is enough. That is... with the right config: stackoverflow.com/a/30209750/6309

                                                                                                                          – VonC
                                                                                                                          Dec 27 '18 at 12:51





                                                                                                                          You don't need all that: a simple git pull is enough. That is... with the right config: stackoverflow.com/a/30209750/6309

                                                                                                                          – VonC
                                                                                                                          Dec 27 '18 at 12:51


















                                                                                                                          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.




                                                                                                                          draft saved


                                                                                                                          draft discarded














                                                                                                                          StackExchange.ready(
                                                                                                                          function () {
                                                                                                                          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f24114676%2fgit-error-failed-to-push-some-refs-to%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

                                                                                                                          List item for chat from Array inside array React Native

                                                                                                                          Thiostrepton

                                                                                                                          Caerphilly