15

After cloning git repository to directory "hggit" and setting the remote origin with

mbm:hggit my name$ git remote add origin [email protected]:"mystringhere"

After editing files I committed the changes (while located in a sub-dir) with

mbm:handelgroup michaelmausler$ git commit -m "first commit"
[master 5a29bc8] first commit
 1 files changed, 2 insertions(+), 2 deletions(-)

I then attempted to push file changes and received the following error

mbm:hggit myname$ git push origin master
error: src refspec master does not match any.
error: failed to push some refs to '[email protected]:"mystringhere"'
5
  • It doesn't look like you've got a ref called "master". Try running "git show-ref" to see what refs you do have. Perhaps the branch you mean is called something else. Commented May 13, 2012 at 1:23
  • i did "git remote add origin" should i have done "git remote add master" instead? Commented May 13, 2012 at 1:35
  • That was probably the right thing to do. What you need to verify is that the branch named "master" exists on the remote named "origin", that branch exists in your local repository, and that you've committed to that branch. Try running gitk. Commented May 13, 2012 at 1:40
  • i cloned it so the branch does exist Commented May 13, 2012 at 3:07
  • When you run "git status" what does it say? Commented May 13, 2012 at 5:41

3 Answers 3

17

use git branch -m to rename your local repository to have the same name you want to push to the remote

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

Comments

14

If git status does indicate that you do have an active master branch (since you did make a first commit after all), check if you made any typo when defining your remote: see "Push origin master error on new repository":

git remote rm origin

Then I recreated the origin, making sure the name of my origin was typed EXACTLY the same way my origin was spelled.

git remote add origin git@....

You can simplify with:

git remote set-url origin git@....

Then you can establish a tracking link between the local branch and the remote tracking branch:

git push -u origin master

You can also push it to a different branch on origin:

git push -u origin master:anotherBranch

Comments

8

You need to make sure that the branch name is the same locally and remotely. So it's not enough to have master branch on remote. You also need this branch locally.

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.