git problem: made mistake with creating branch and cannot push to master anymore
I did
git checkout -b foo origin/master
git push origin foo
to create a branch and push it to the remote repo. This is obviously the wrong way to do it (I'm a git beginner). But apart from being wrong, it created a much more serious problem: Now we cannot push to master anymore!
Deleting the new branch ("foo") doesn't help.
Cloning a fresh repo doesn't help as well.
Another info on a side effect which might help to identify the problem: Unfuddle (a git hosting site, similar to github) shows the newly created branch as HEAD. And after deleting that branch, master is shown as HEAD again, but every other afterwards correctly created branch (git branch foo
and git push origin foo
) is shown as HEAD again ...
No one can currently push t开发者_JAVA百科o master, it's not just me.
Google couldn't help so far ... Can you?
Thanks a lot!
Update: This problem has resolved itself by committing something ... But we still don't know what went wrong and would be interested in an explanation. But obviously this has lost its urgency.
To answer your questions:
- No, there was no error message at all when pushing. It just didn't do it.
git ls-remote <remote>
only showed what we already knew, that foo was now HEAD.
Actually your first command created a so called tracking branch named foo that is going to track remote branch master via origin/master reference
That means that you now have a relationship between them allowing you to use parameterless push/pull commands
Your second command created a branch foo on the remote side and redefined the relationship, so now the local foo is pushing to remote foo but can pull directly from master. You can see this by executing:
git remote show origin
I don't know what your final goal was, but i would recommend to use a clean topic branch approach instead of trying to link topic branches to remote master.
So instead of what you did, you had to probably execute:
git checkout -b foo master #create topic branch foo from the current state of local master
git push origin foo #create remote branch foo and setup direct relationship, if you really need to have it on the remote repo, but that's questionable
So i would recommend the following workflow:
git checkout foo
...commit, commit...
git checkout master
git pull #to update local master in case if there were changes made while you were working on foo
git merge foo # to merge foo changes into master
git push # push local master to remote
You can't push because you only have created a local branch. You need remote as well if that's what you want. You need to create remote branch, and set your local to track it:
git push origin origin:refs/heads/foo
git checkout --track -b foo origin/foo
git push
If you want to push foo to master you have to do
git push origin foo:master
精彩评论