Search code examples
gitgithubversion-controlpushcommit

Accidentally executed "Git push origin master" while on branch off master


I created a local Git branch off master (lets call it BranchB). I then committed my changes on that branch (to BranchB). But when it came for the time to push to the remote repository, too much coffee got to me, and I wrote git push origin master instead of just git push to push the new branch to the repository.

I then went into GitHub to see the commits on master. The changes that I recently accidentally pushed to master did not appear here?

So what exactly happened when I pushed to master while on Branch B? Does that just push the commits that were done on master since I specified master.


Solution

  • The <refspec> you gave here as a parameter for your push is master, where the full canonical form would have been <src>:<dst>, <src> being the source of the push and <dst> the destination ref. When you omit one, git assumes your parameter is <src> and that no <dst> has been given. In that case, and if the branch has a <repository>.push config set (so in most cases), that ref is used as the source for your push.

    So yes, it pushed master (with no new commits) to its remote counterpart. Harmless no-op.

    (Maybe check your own config with git config -l | grep origin or something along these lines.)

    You would have pushed BranchB on master with an explicit :

    git push origin BranchB:master
    

    That's what I understand from the doc, namely the <refspec> paragraph in git-push man page. Seems to make sense with your results.