Is there a way to make a local branch immutable?

浪尽此生 提交于 2019-12-05 13:41:20

You cannot make a local branch immutable (there is no local hook that runs before a merge operation). However, if you're not going to be making commits on the branch, just don't check it out. If you have it checked out already, delete the local branch:

$ git checkout some-other-branch
$ git branch -D master

Now when you attempt to checkout the master branch it will fail:

$ git checkout master
error: pathspec 'master' did not match any file(s) known to git.

If you ever need to refer to the upstream master branch (e.g., for a diff), you can just refer to it directly:

$ git diff origin/master
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!