Reputation: 102795
If I have created and pushed a topic branch that has been merged to master long time ago, can I safely just run git push origin :foobranch
without fearing that it somehow deletes data that is merged to master or some other branch?
Upvotes: 1
Views: 1108
Reputation: 467231
Yes, you can safely delete a branch that has been merged into another branch. Branches are like movable pointers into the commit graph, and if you delete a branch, it's just removing that pointer. The commit graph remains, and in your case the master
branch will still contain the history of the branch you've removed.
Upvotes: 2
Reputation: 17624
deleting a commit or a branch won't affect other commits on other branches, even if that commit was shared among branches, or the branch was merged into other branches.
Upvotes: 1
Reputation: 121720
It is perfectly safe.
Any commit is linked to a tree (ie, your project files), and potentially, several commits point to the same tree. It is only when no commit links to a tree anymore that it may be garbage collected.
If you still need to recollect it somehow and don't even have a local ref to the commit, there is the reflog, which is cleaned up only after 90 days (I think) by default.
Upvotes: 1
Reputation: 131891
As long as there are no outstanding commits, its safe. If you want to be sure
git checkout master
git merge foobranch
This should result in a fast-forward merge (that does not affect the history). If not, maybe there were unmerged commits. However, now you are completely safe
git branch -d foobranch
git push origin :foobranch
Upvotes: 2