Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Why do "new branches" push to previously deleted ones?

I have deleted a branch on Github but when I push a new commit to a branch with the same name (assuming it should be new), it still lists activity as if its the previously (deleted) one. How can I fully remove a branch on github so this doesn’t occur or force it to create a new branch with the same name?

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

When I push a new commit to a branch with the same name (assuming it
should be new), it still lists activity as if its the previously
(deleted) one.

Yes, this is just how branches in Git (and on Github) work.

In Git, a branch is nothing but a name (which points to some commit). If you delete a branch in a repository and re-create it, Git has no way of knowing that the branch "feature1" you just re-created is supposed to be different from "feature1" that was deleted yesterday.

There is no way around this. The usual way to resolve this is to not reuse branch names. Re-using branch names is (IMHO) problematic anyway, because it can quickly become confusing. So just do not do this :-).


Note that there is nothing inherently wrong with having long-running and constantly changing branches if you want to – for example, the development of Git itself uses several long-running branches which change regularly ("next", "seen"…). However, if one of these branches is deleted and re-created (which can indeed happen), Git itself will not know about it, therefore the Git project explicitly documents when and how these branches may change, so developers are aware.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading