Alpha
Alpha

Reputation: 14066

Does deleting branch from server delete history of that branch forever?

I created a branch 'test' (just for learning purpose) & pushed it to origin server. For branch 'test' I have two commits & I pushed them to origin. But I don't want those commits hence also that branch. Hence now, I'll delete branch 'test' from origin (and also locally by 'git branch -d test'):

git push origin :test

Will this delete everything about that branch (including those both commits) forever?

Also, can I create a branch with same name i.e. 'test'?

Upvotes: 2

Views: 628

Answers (1)

AD7six
AD7six

Reputation: 66299

No, deleting branches does not delete commits

A branch is just a pointer to a commit - if you delete the branch, the commits still exist and can be accessed directly by the commit hash.

Over time, git automatically deletes un-referenced commits/objects (garbage collection) but this isn't immediate. Github has a helpful page on the topic if you want more information on how to permanently delete pushed changes but you don't need to do this unless you specifically want to obliterate the contents of your unwanted and now orphaned commits.

Yes you can create a new branch with an old name

If you've deleted a branch and want to recreate it with a different name - yes you can.

If the remote branch still exists and you want to publish to it, you'll need to force push (git push -f) the first time you push to the remote as the remote branch will probably not have a common history with your "new" branch with the same name.

Upvotes: 5

Related Questions