1

I am using Git Bash on Windows 10. I have cloned a repository to my PC, added files to it and made commits.

When I try the command:

git push origin master

I get this error:

fatal: couldn't find remote ref master

But if I try a simple git push, there is no error and the changes are reflected in my remote repo. The same is true with the pull command. What's going wrong and how do I fix this?

Edit: Based on the comments and the answers, I am adding this info.

When I do a git branch -avv I get the following output:

* main                f42878d [origin/main] Added some more Week 1 problems
  remotes/origin/HEAD -> origin/main
  remotes/origin/main f42878d Added some more Week 1 problems

So, I tried what one of the answers suggested, which is to try git push origin main instead of git push origin master. This is my output:

warning: setting remote service path not supported by protocol
Logon failed, use ctrl+c to cancel basic credential prompt.
warning: setting remote service path not supported by protocol
Everything up-to-date

It does seem to work, but there are warnings before that. I googled the warning and found this Stackoverflow answer. Based on the accepted answer, I ran GitBash as administrator, but the warning persists. What happens is that the authentication happens twice: once normally through a GitHub Login dialog box where I put my username and password. This fails, then an OpenSSH dialog box where I provide my username and password. This works.

I am new to Git Bash, so I have no idea where to go from here.

5
  • 2
    What's the tracking branch on the remote for your current branch? Are you on master locally, even? Commented Apr 20, 2021 at 12:29
  • 1
    Can we see the result of git branch -avv ? Commented Apr 20, 2021 at 13:29
  • I have edited the question with the updated information. Commented Apr 20, 2021 at 16:58
  • 1
    You indeed don't have a remote master, so that error shouldn't be surprising. It's not really clear why, if you can just git push (i.e. the correct tracking branch is set), it's a problem that you can't git push <remote> <branch>). Commented Apr 20, 2021 at 17:24
  • 1
    This looks like a Windows ssh issue, rather than anything to do with Git itself. (Git for Windows tends to come with a version of ssh—just like it comes with a version of bash, which Windows people call "git bash" but it's really just bash-for-Windows—because the standard Windows tools were, for so many decades, so poor. Modern Windows has better tools now, apparently, but I don't actually use Windows so I don't have the whole answer for you.) Commented Apr 21, 2021 at 0:53

1 Answer 1

1

Try using git push origin main This is because in GitHub master is addressed as main.

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

3 Comments

It's not guaranteed that the remote will have a main branch, either, or that if it exists it matches what you're on locally. "master is addressed as main" is simply not true; the default branch for newly-created repos is now named main, there isn't a branch named master by default.
@jonrsharpe this answer did seem to work though, although I received warnings before that. I have made edits to the question accordingly.
@justauser it will work if there's a main branch on the remote and if it is the correct branch for the local branch you're trying to push to it. But it's not a general solution and contains false information. Also that's the point of setting a tracking branch, so you don't have to specify every time.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.