13

I made a new branch, checked it out and made a commit:

git branch my-branch [HASH]
git checkout my-branch
git commit -am "Add some stuff to my new branch"

However, I can't push it to github. git push origin my-branch returns:

error: src refspec branch does not match any.
error: failed to push some refs to 'https://github.com/Me/my-project.git'

git show-refs looks like this:

[HASH] refs/heads/my-branch
[HASH] refs/heads/master
[HASH] refs/heads/some-branch
[HASH] refs/remotes/origin/master
[HASH] refs/remotes/origin/some-branch
[HASH] refs/stash

What do I need to do?

fredley
  • 31,101
  • 42
  • 135
  • 231

3 Answers3

12

Here is the command you would execute to push all of the changes from your local branch ("my-branch") to a "my-branch" branch on the GitHub repository:

git push -u origin my-branch
Mario Kutlev
  • 4,459
  • 6
  • 42
  • 60
5

The branch doesn't exist on github, when you push git checks the refs of origin for your branch and doesn't find it.

Add the branch as a remote branch:

git 1.8.x

git branch -u origin/my-branch my-branch

git 1.7.x

git branch --set-upstream my-branch origin/my-branch

Now you can push.

Peter van der Does
  • 13,302
  • 4
  • 37
  • 42
0

There is an error in command line parsing. As you can see in this message:

error: src refspec branch does not match any.

git tries to push a branch with the name branch, not my-branch. What OS/shell are you running? Maybe try

git push origin "my-branch"
Chronial
  • 60,064
  • 13
  • 82
  • 88