1

In my project I created a new branch for a new feature, finished the feature and merged the branch back into my development branch. I then followed the instructions to delete the branch locally and on my github origin repo.

I then noticed that all mentions of my branch, both locally and remotely, are completely gone. I can't see any indication that the branch even existed at some point of time. This is scary because what if I bring another developer on (or hell if I even do this) and instead of deleting a feature branch on GitHub he deletes the development branch. The only indication I will have is one less branch showing up with no indication of why.

One of the major reasons to use source control is to have a complete history of everything that happened to your source, and this seems to run contrary to it, unless I am missing something. What I would prefer is some way to mark a branch as closed so it doesn't accept any more changes, but you still have the log of the progression of the branch, who closed it and why it was closed (did the feature not work out correctly and it had to be redone, was it finished, etc..) and who closed it.

Since I can't find any way to do that is there any way to at least secure who is allowed to delete a branch and who doesn't have access to it? Or is there a way to view deleted branches?

JasonMArcher
  • 14,195
  • 22
  • 56
  • 52
KallDrexx
  • 27,229
  • 33
  • 143
  • 254
  • Similar to http://stackoverflow.com/questions/2471340/is-there-a-way-to-lock-a-branch-in-git. – ssapkota Jun 13 '11 at 15:34
  • try creating a branch, making a test commit, deleting the branch, and then doing a `git reflog`. Pretty sure it'll have special hashes still available. Not a complete answer through, so certainly a good question. – Kzqai Jun 13 '11 at 15:38
  • Unfortunately, gitolite (solution in the linked question) seems to require me to provide my own server where I can host and run git repositories. As I have no experience doing this, and cannot match the reliability of github, I don't really see this being useful until my operations become much bigger. – KallDrexx Jun 13 '11 at 15:39

2 Answers2

2

If the other developer deletes a branch on Github, you'd still have your own copy of it in your local repo, and could just re-push it to Github.

Amber
  • 507,862
  • 82
  • 626
  • 550
  • 1
    That's not necessarily true, if for instance I replaced my machine in between it happening, or I was cleaning up stuff locally. – KallDrexx Jun 13 '11 at 15:36
  • Well, if you're worried about security but still want to use Github and give other people access, that's basically your main option. – Amber Jun 13 '11 at 15:40
  • 1
    (You could, of course, just not give other people access and require them to have their own public repo that you merge their work from.) – Amber Jun 13 '11 at 15:41
  • That also doesn't solve the issue of me accidentally deleting the wrong branch when I am the only developer – KallDrexx Jun 13 '11 at 15:41
  • 1
    If you delete the wrong branch, the deletion command locally will tell you what SHA the branch was pointing to; you can re-create the branch with `git branch `. – Amber Jun 13 '11 at 15:45
2

Deleting a branch in git does really delete the branch. If this is not what you want to do, don't delete the branch. However, deleting a branch by itself doesn't remove any of your project history; it just removes the reference to the end of the branch. All the commits on the branch are still there; there's just no obvious way to find them.

You can't prevent someone who has access to your repository from deleting a branch. That's why it's usual in github for every person to have their own repository to work in. If a branch is deleted, you're the one who did it.

If you delete a branch yourself by mistake, you can get it back if you know the commit id of the tip of the branch (which will be recorded in the commit where you merged it into your main development line, or in the reflog). Create and checkout a new branch with the name of the deleted branch, and use git reset to tie that branch name with the tip commit again.

From your question, it seems like you want to keep track of the state of the branch forever. The right way to do that is to create a tag at the end of the branch. You can then delete the branch but the reference to the tip (and all its history) will live on in the tag.

antlersoft
  • 14,636
  • 4
  • 35
  • 55