Dean Strydom
Dean Strydom

Reputation: 305

Can I delete a branch when there is another branching from it?

I am not so familiar with version control. If I have my own branch from the master and eventually screw up something forcing me having to branch from an earlier point, can I safely delete my main branch to replace it with the new one? In other words if the master is branch A and I branch from the master as B and eventually branch from B as C, can I delete B in-order for C to become the main branch? Or will that result in C also being deleted?

Upvotes: 1

Views: 601

Answers (1)

Florian Callewaert
Florian Callewaert

Reputation: 424

In my opinion, repository are only a list of commit files. In Git, branch are pointer on commit. Commit store changes since the last commit.

Remove the branch "B" only remove the pointer "B". It doesn't remove commits and files. So remove the pointer "B" has no effect on the pointer "C".

Then you can remove the branch "B" without removing the branch "C". But changes made in branch "B" after creating the branch "C" will be lost.

An simple example : mkdir testBranchGit cd testBranchGit git init touch 01.md git add 01.md git commit -m "01.md" git checkout -b branchB touch 02.md git add 02.md git commit -m "02.md" git checkout -b branchC branchB touch 03.md git add 03.md git commit -m "03.md" git branch -d branchB ls git branch --list git log

Upvotes: 2

Related Questions