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?
Push a new Git branch to a remote repo Clone the remote Git repo locally. Create a new branch with the branch, switch or checkout commands. Perform a git push with the –set-upstream option to set the remote repo for the new branch. Continue to perform Git commits locally on the new branch.
In order to push your branch to another remote branch, use the “git push” command and specify the remote name, the name of your local branch as the name of the remote branch.
To push the branch or you can say to push the changes in the branch to the Github repo you have to run this command “git push origin <the branch name>” in our case the branch name is “main”. After pushing the changes the repo will look like and this is how you can push a branch to a remotely hosted GitHub repository.
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
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.
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