Reputation: 27813
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?
Upvotes: 1
Views: 123
Reputation: 14786
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.
Upvotes: 2
Reputation: 526763
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.
Upvotes: 2