0

I can't push my repo to bitbucket. Error of "failed to push refs"

I checked error: failed to push some refs but the answer there doesn't apply to me, as it speaks of 777 permissions and i'm on windows.

I have used bitbucket and git before some years back. And there have been some changes in the GUI of the bitbucket website. It used to be that when I created a repo in bitbucket, then bitbucket would give a few commands that I could paste in like git remote origin... and some URL.. (I would use the word bitbucket instead of origin). But bitbucket's design has changed and I can't see those commands now and I can't get it to work.

(Following a suggestion I saw in a youtube video), to find the line to add the git "remote", I went to the clone option in the GUI, and without doing any clone, I got the URL of https://[email protected]/gbatha12/reminderonlaptopdownstairs.git

And then I did git remote add bitbucket https://[email protected]/gbatha12/reminderonlaptopdownstairs.git

As you see below.

C:\Users\User\source\repos\RemindProj\RemindProj>git init Initialized empty Git repository in C:/Users/User/source/repos/RemindProj/RemindProj/.git/ C:\Users\User\source\repos\RemindProj\RemindProj>git add -A C:\Users\User\source\repos\RemindProj\RemindProj>git push bitbucket master error: src refspec master does not match any error: failed to push some refs to 'bitbucket' (ok that's understandable I have to create a commit) C:\Users\User\source\repos\RemindProg\RemindProg>git commit -m "earlyversion" [master (root-commit) c8b3dc1] earlyversion 25 files changed, 596 insertions(+) create mode 100644 App.config create mode 100644 Form1.Designer.cs create mode 100644 Form1.cs create mode 100644 Form1.resx create mode 100644 Program.cs create mode 100644 Properties/AssemblyInfo.cs create mode 100644 Properties/Resources.Designer.cs create mode 100644 Properties/Resources.resx create mode 100644 Properties/Settings.Designer.cs create mode 100644 Properties/Settings.settings create mode 100644 RemindProj.csproj create mode 100644 bin/Debug/RemindProg.exe create mode 100644 bin/Debug/RemindProg.exe.config create mode 100644 bin/Debug/RemindProg.pdb create mode 100644 obj/Debug/.NETFramework,Version=v4.7.2.AssemblyAttributes.cs create mode 100644 obj/Debug/DesignTimeResolveAssemblyReferences.cache create mode 100644 obj/Debug/DesignTimeResolveAssemblyReferencesInput.cache create mode 100644 obj/Debug/RemindProg.Form1.resources C:\Users\User\source\repos\RemindProj\RemindProj>git push bitbucket master fatal: 'bitbucket' does not appear to be a git repository fatal: Could not read from remote repository. create mode 100644 obj/Debug/RemindProg.Properties.Resources.resources create mode 100644 obj/Debug/RemindProg.csproj.CoreCompileInputs.cache create mode 100644 obj/Debug/RemindProg.csproj.FileListAbsolute.txt create mode 100644 obj/Debug/RemindProg.csproj.GenerateResource.cache create mode 100644 obj/Debug/RemindProg.csprojAssemblyReference.cache create mode 100644 obj/Debug/RemindProg.exe create mode 100644 obj/Debug/RemindProg.pdb Please make sure you have the correct access rights and the repository exists. OK that's understandable I have to add the git "remote". C:\Users\User\source\repos\RemindProg\RemindProg>git remote add bitbucket https://[email protected]/gbatha12/reminderonlaptopdownst airs.git C:\Users\User\source\repos\RemindProg\RemindProg>git push bitbucket master To https://bitbucket.org/gbatha12/reminderonlaptopdownstairs.git ! [rejected] master -> master (fetch first) error: failed to push some refs to 'https://bitbucket.org/gbatha12/reminderonlaptopdownstairs.git' hint: Updates were rejected because the remote contains work that you do hint: not have locally. This is usually caused by another repository pushing hint: to the same ref. You may want to first integrate the remote changes hint: (e.g., 'git pull ...') before pushing again. hint: See the 'Note about fast-forwards' in 'git push --help' for details. C:\Users\User\source\repos\RemindProg\RemindProg> 

So the message says "the remote contains work that you do not have locally."

But if I look at the repo on the bitbucket website, I just see a .gitignore file.

I tried deleting that .gitignore file that exists on the remote site but not locally.

And then doing git push bitbucket master but same error.

I know the error message, suggests to do a git pull, though i'm a bit reluctant to because my local area has some early version of my program. Normally when I do a pull it's when I have no program locally. And anyhow I never had this error in the past when using git and bitbucket.

0

3 Answers 3

2

To dismiss this error, the best way is to execute git pull. Then you will have your .gitignore file from your BitBucket repository also local.

But as far as I have read in your question, you don't want this .gitignore-file in your repository. So remove the .gitignore-file now local (after git pull you will have this .gitignore-file local) and git push this changes. Then you have removed the .gitignore-file.

And now you are able, to git push the other new files to the remote BitBucket repository, because you don't have contains work, that you do not have locally.


What you also can do, is git push -f (-f for force). That will over push the remote repository with the local repository. But this should be used with caution.

Note from Barlop/OP. What I did was the solution of doing git push -f. Safe in my case as it's my own personal project and a new repo. I didn't do a pull.

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

3 Comments

Thanks.. The git push -f worked. So git push -f bitbucket master Removing the gitignore file didn't work because I see the issue is that there is a commit there on the remote by default. (or two commits if I remove the .gitignore file). If when creating the bitbucket repo I don't go with the default and I choose to not create the .gitignore, then the remote repo is blank no commits like bitbucket used to be. It's a personal project and a new repo so git push -f is fine. Thanks. I did not do git pull
I created a repository in BitBucket for testing purposes. There you will be asked when creating a repository whether you want to add a .gitignore-file or not. Then BitBucket automatically creates an "initial commit" with .gitignore-file and also a README file. But if you then git push -f from local repository, the .gitignore-file in BitBucket is overwritten and disappears from the repository. Don't know, why your .gitignore-file is not removed...
I meant removing the .gitignore file from within the bitbucket website GUI left a commit there. But yeah git push -f does remove everything there including the .gitignore file. Thanks
0

You have a good part of the answer in the Git error message:

Updates were rejected because the remote contains work that you do not have locally. This is usually caused by another repository pushing to the same ref. You may want to first integrate the remote changes (e.g., 'git pull ...') before pushing again.

You first need to pull the existing commits from the remote in your local repository. For instance by using git pull.

i'm a bit reluctant to because my local area has some early version of my program

If your local work is commited (even if not pushed), you cannot lose it by doing a git pull. Depending on your config, Git will either rebase or merge your work and the commits from the remote.


OR if you don't care about what is in the remote as you seems to say, you can use git push --force-with-lease to "overwrite" the remote with the content of your local repository.

Note: don't do that if other people have already checked out your repository and started using it. Seems it's not your case though.

3 Comments

This like my other projects is just a personal project. I am the only person working on it. I don't think I had to do a pull before doing a push before. I think I see what's going on.. That project bitbucket created with .gitignore and a pre-existing commit. Whereas if when creating a project I choose to not include a .gitignore, then the project won't include any pre-existing commits , which is how bitbucket was before.
I am still getting an error that it can't push it pastebin.com/raw/h9PQGnPF
this one you suggested git push --force-with-lease bitbucket master didn't work but doing git push -f bitbucket master which another answer suggested, worked
0

If any of the other answers doesn't work for you, check your branch by running git branch.

In my case I was trying to push branch main (default branch created when running git init) to branch master.

Error I received read:

git push -u origin master error: src refspec master does not match any error: failed to push some refs to 'bitbucket.org:... 

To resolve this I created a new master branch, merged main into master and pushed from master.

*** I also deleted the main branch post pushing to remote with git branch -D main

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.