可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
This question already has an answer here:
I am using git and I am doing my development work, which I don't want to push, even by mistake. Is there a method to disable push in certain local repository. One method is to rename the branch, another is to undo push if one does it by mistake, but I hope there should be a more direct method.
回答1:
The following command will let pulls work, but pushes will try to use the URL no_push and fail:
git remote set-url --push origin no_push
回答2:
Depending on the remote, you may be able to reset its URL to use the read-only Git protocol instead of SSH or HTTPS. E.g., for a project on GitHub, do
git remote set-url git://github.com/Team/Project.git
where is commonly origin. git remote -v will give you a list of remotes; those that start with https or have the form @: usually allow pushing.
回答3:
In git 2.0, git branch --unset-upstream will prevent git push working against the current branch. (This will also work in versions of git >= 1.8, if push.default is set to either upstream or simple.)
# git push works $ git push Everything up-to-date # unset upstream $ git branch --unset-upstream # git push fails $ git push fatal: The current branch master has no upstream branch. To push the current branch and set the remote as upstream, use git push --set-upstream origin master
(Note that git push origin master will still work; this merely blocks the abbreviated git push. It probably also prevents git status indicators that appear in the shell prompt from indicating that you are ahead of or behind the remote.)