Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How could I mark a git branch as deprecated

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?

like image 342
vyakhir Avatar asked Jun 02 '15 16:06

vyakhir


People also ask

Can you archive a branch in git?

The git archive command is a Git command line utility that will create an archive file from specified Git Refs like, commits, branches, or trees.

How do I modify a branch?

Git Branch Rename Command The steps to change a git branch name are: Rename the Git branch locally with the git branch -m new-branch-name command. Push the new branch to your GitHub or GitLab repo. Delete the branch with the old name from your remote repo.


1 Answers

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).

like image 184
DIMMSum Avatar answered Sep 20 '22 12:09

DIMMSum