A Git command needs to be run on a specific repository, so this error typically occurs when a Git command is run in a directory that Git doesn't know about. In these cases, the fix is to make sure that you are both working in the correct folder and that you set up your repository right.
If git push origin master not working , all you need to do is edit that file with your favourite editor and change the URL = setting to your new location. Assuming the new repository is correctly set up and you have your URL right, you'll easily be able to push and pull to and from your new remote location.
If you get a failed to push some refs to error, the main thing to do is git pull to bring your local repo up to date with the remote. Avoid employing the --force flag when using git pull and prevent other developers' accidental overwrites of committed features.
In order to push a Git branch to remote, you need to execute the “git push” command and specify the remote as well as the branch name to be pushed. If you are not already on the branch that you want to push, you can execute the “git checkout” command to switch to your branch.
In my case, GitHub was down by the time I was trying to push.
Just check https://www.githubstatus.com/ to know about GitHub site status.
When it's up you'll be able to push.
This fixed it for me:
git gc
That will start a garbage collection that resolved my error.
Make sure your repo is online.
I got this error today when attempting to push to github and then couldn't even browse the site without getting their unicorn error message.
Try rebase the current branch on top of the upstream branch after pull, e.g.
git pull origin master -r
then push it again:
git push origin master
I raised this with GitHub in relation to http://blastedbio.blogspot.co.uk/2016/05/sync-github-mirror-with-cron.html and it turned out to be due to protected branch settings. GitHub have improved the error message:
$ git push mirror master
Counting objects: 391, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (391/391), done.
Writing objects: 100% (391/391), 99.28 KiB | 0 bytes/s, done.
Total 391 (delta 298), reused 0 (delta 0)
remote: error: GH006: Protected branch update failed for refs/heads/master.
remote: error: You're not authorized to push to this branch. Visit https://help.github.com/articles/about-protected-branches/ for more information.
To [email protected]:HuttonICS/biopython.git
! [remote rejected] master -> master (protected branch hook declined)
error: failed to push some refs to '[email protected]:HuttonICS/biopython.git'
If you try again now you ought to get a more constructive error report. In my case I needed to adjust my protected branch settings as per https://help.github.com/articles/about-protected-branches/
From my experience, there is now (2019) some rate limit on GitHub that causes this problem for me when mass-pushing tens of huge repositories. It can also cause "cannot read" problem in random cases.
When I delay for 30 seconds before each push, both problems go away and I can continue with hundreds of repos without a glitch (sigh, don't even ask).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With