Reputation: 1793
Is there a way I can mark one of my git branches as deprecated so if anyone tries to push to it (or ideally even if someone commits into it)? I want git to show a warning saying that the branch is deprecated and should not be used. I need this for a particular branch only, not for entire repo.
Would you please advise how I could do so?
Upvotes: 7
Views: 10371
Reputation: 1626
If the branch is deprecated and people are still trying to push to it, it sounds like there's some kind of breakdown in your dev process. That being said, it sounds like you can address this using a git hook.
One option is to use a client side hook such as a pre-commit
hook that would be run on the dev's local machine when they tried to commit. The idea is that you check if the branch they're committing onto matches (using regex) this or any other deprecated branches. If so, return a non-zero exit status to block the commit.
Alternatively, if you wanted to prevent someone from pushing an update to the branch on the remote repo, you could use an update
hook.
To see examples of these hooks, check the .git/hooks
directory on any repo (the example hook will be hook-name.example
).
Upvotes: 5