1099

I can't push now, though I could do it yesterday.

When I use git push origin master, I get an error:

git remote -v 

Output:

origin https://github.com/REDACTED.git (fetch) origin https://github.com/REDACTED.git (push) 

And:

git push origin master 

Output:

Username for 'https://github.com': REDACTED Password for 'https://[email protected]': To https://github.com/REDACTED.git ! [rejected] master -> master (non-fast-forward) error: failed to push some refs to 'https://github.com/REDACTED.git' hint: Updates were rejected because the tip of your current branch is behind hint: its remote counterpart. Integrate the remote changes (e.g. hint: 'git pull ...') before pushing again. hint: See the 'Note about fast-forwards' in 'git push --help' for details. 

My working directory and remote repository looks like:

Screenshot of Windows file folder with these directories: .git, css, js. And these files: index.php, readme, setsu.php. The word "local" with an arrow points to the css-folder. Below, screenshot with heading "github", and a css-folder and index.php-file

13
  • 21
    looks like your local repo is not in sync with the git repo. did you try to do git pull ? Commented Jun 9, 2014 at 6:25
  • 9
    Do check this similar question - stackoverflow.com/questions/18588974/… Commented Jun 9, 2014 at 6:33
  • 5
    @R11G thank you sir! this link helped me stackoverflow.com/a/18589043/3626672 Commented Jun 9, 2014 at 6:42
  • 5
    I got that error on a new repo. This helped: stackoverflow.com/a/6518774/2067690 Commented Jul 8, 2015 at 20:38
  • 22
    hey, if you find this on Google at this time, check if GitHub is down -> githubstatus.com Commented Aug 10, 2021 at 15:59

69 Answers 69

1 2
3
0

In my case the problem was that (strangely) there was no branch called master. I took the repository from GitHub.

Sign up to request clarification or add additional context in comments.

1 Comment

What was the solution?
0

I was pushing an existing branch with a typo, 'evelop', which I did not have checked out yet, and instead, I wanted to push a branch called 'envelope'.

So the branch must exist and checked out at the local working copy in order to be able to be pushed, of course. Therefore the solution to that error is to not make a typo.

Comments

0

In my case: a tag was named the same as an existing branch. Renaming the branch (git checkout with an other name) and removing the clashing named branch (git branch -d $branchname) solved the issue: git pushing the tag went ok.

Comments

0

Is your push linked with your Jira story? If yes, check the Jira workflow condition.

The administrator may configure to allow only push only based on some workflow.

Comments

-1

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 it incorrectly and you want to remove the local repository, use the following steps.

Remove the local repository on 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/<username>/XXXX20.git
  7. git push -u origin master

Comments

-1

For me I just had to checkout into another branch and then comeback, and then it worked, I could push with no issues.

Please try the simple things before using --force and such

Comments

-1

My case here is that I am trying to upload files that are too large at the same time.

So the problem is solved when they are split and uploaded separately.


Update

Hi @JeremyCaney, thank you for your kind reminder. Please find further elaboration below.

1. Certainty of approach uniqueness: I can confirm that the approach I presented earlier has not been previously provided for this specific question.

2. Distinction of approach: While the uniqueness of my approach may not be the primary focus, it is worth noting that the reason behind the 'git error: failed to push some refs to remote' can vary, and the solution I offered addresses one possible cause.

3. Preferred circumstances for the approach: This approach is particularly effective for handling large files. Although I cannot provide an exact file size threshold, based on my experience, I have encountered difficulties when attempting to upload files of approximately 4GB at once.

4. Insufficiency of previous answers: The previous answers provided effective solutions for most issues, but unfortunately, they did not address the specific problem I encountered.

2 Comments

Thank you for your interest in contributing to the Stack Overflow community. This question already has quite a few answers—including one that has been extensively validated by the community. Are you certain your approach hasn’t been given previously? If so, it would be useful to explain how your approach is different, under what circumstances your approach might be preferred, and/or why you think the previous answers aren’t sufficient. Can you kindly edit your answer to offer an explanation?
This does not really answer the question. If you have a different question, you can ask it by clicking Ask Question. To get notified when this question gets new answers, you can follow this question. Once you have enough reputation, you can also add a bounty to draw more attention to this question. - From Review
-2

Works in Github

I'm assuming that you're utilizing GitHub for your repo.

A potential, albeit rare, cause of the error you're encountering might be due to protective rules set on the branch to which you are pushing, which you may have inadvertently forgotten about.

If this is the case, to resolve it, it's necessary to completely remove these rules. Merely editing the rule or deselecting options within the rule page is insufficient to address the issue.

Step 1:

Go to the "Setting" of the repo

enter image description here

Step 2:

In "Code and automation" menu find the "Branches" item

enter image description here

step 3:

You should verify whether there's a match between the existing rule patterns and your branch name. If you find a match, delete that rule as demonstrated in the picture above.

Remember to capture a screenshot of the configured rules before you delete them.

step 4:

Since you're removing the protection rule temporarily, it implies you understand your actions and might need to reestablish that rule following your push operation.

Note

To resolve the error, you might consider editing the rule by unchecking the active boxes; however, this approach is ineffective. Only complete delete works!

enter image description here

Comments

-3

Getting an error on git push -u origin main? Try this solution. It will work 100%.

git push origin master, change it to git push origin main

How to change Main?

git branch -M main

Comments

1 2
3

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.