Git push error '[remote rejected] master -> master (branch is currently checked out)'

前端 未结 30 2930
半阙折子戏
半阙折子戏 2020-11-22 00:07

Yesterday, I posted a question on how to clone a Git repository from one of my machines to another, How can I \'git clone\' from another machine?.

I am now

30条回答
  •  天命终不由人
    2020-11-22 00:34

    The error message describes what has happened. More modern versions of Git refuse to update a branch via a push if that branch is checked out.

    The easiest way to work between two non-bare repositories is either to

    1. always update the repositories by pull (or fetch and merge) or, if you have to,

    2. by pushing to a separate branch (an import branch) and then merging that branch into the master branch on the remote machine.

    The reason for this restriction is that the push operation operates only on the remote Git repository, it doesn't have access to the index and working tree. So, if allowed, a push on the checked-out branch would change the HEAD to be inconsistent with the index and working tree on the remote repository.

    This would make it very easy to accidentally commit a change that undoes all of the pushed changes and also makes it very difficult to distinguish between any local changes that have not been committed and differences between the new HEAD, the index and the working tree that have been caused by push moving HEAD.

提交回复
热议问题