How to disable a branch on Github?

Asked

Viewed 123 times

0

Good afternoon,

I have a repository on Github with a main branch, and the idea is that with each new Feature, this is done from a new branch, which at the end should be merged with the main branch, through the merge.

But the question is, if it is possible, after merging, to disable that branch, but not to delete it.

Example:

git checkout -b novaFeature

Made the change and then

git commit -m "Nova Feature"
git push origin novaFeature
git checkout main
git merge novaFeature

Until then everything is fine, except that if every new Eature, if it is done, will generate a lot of branchs that in my view can end up polluting and messing up the repository.

I wanted to know if there is any way to after merge the branch is inactive, but not delete it.

My first time posting here, I hope I managed to ask the question correctly.

Hug to all of you!

  • 1

    If you don’t want to delete the branch, just don’t touch it anymore. But if you don’t want them to stay in the repository, delete :-)

  • 1
  • @hkotsubo, it makes sense.

  • @Pedrosanção I took a look at this link, but I didn’t want to exclude, I believe it would be something closer to Ruan Montelo’s answer, maybe to stop a branch from receiving pushes.

2 answers

0


From experience (and as mentioned in the @hkotsubo comment), if you don’t want a local and/or remote branch, just delete the branch as there is no way disable, only prevent pushes are made for the remote repository of the branch in question. The point of having a versioning system, dealing with the Git in this post, is just have a history of changes of all shared versions so that this is not necessary.

If you want a more "clean" history of your versions, especially the most important ones (such as the branch main in the example of Github) it is possible to approve a Pull Request (or merge) using rebase.

Github’s own tool gives you the option to do this and delete the branch in sequence while approving a Pull Request, I recommend searching on to keep a concise history of the main version of the project.

I hope I’ve helped in some way.

  • "just prevent pushes from being made into the remote repository of the branch in question" .

  • I edited the reply to include the requested reference.

  • 1

    Thanks @Ruan-montelo, that would be right, my project is private, and so this functionality is only for Github Pro accounts. Vlw!

0

The command to delete a remote branch is push. How the branch parameter can use the : to use different names for the local and remote branch, it is also possible to delete.

git push origin :novaFeature

As there is nothing before the : it is interpreted as "send anything to the novaFeature branch", deleting on the remote server.

  • Understood, but in this case did not want to delete the branch, would leave it inactive, as this link, but thanks for the help!

  • really, I misunderstood the question, but it’s okay that other people who fall here

Browser other questions tagged

You are not signed in. Login or sign up in order to post.