Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can you re-use deleted Git branch names?

Tags:

git

branch

If I create a Git branch named "foobar", do some work in it, merge it back into my development branch and then delete the foobar branch, can I create another branch at some future point with the same name "foobar" or will this confuse Git?

like image 719
Jim Avatar asked Oct 01 '15 00:10

Jim


3 Answers

In git, a branch name is simply a pointer to a particular commit. Adding things to the branch simply moves that pointer to a new commit. Deleting the branch simply means deleting the pointer. If you re-create that same branch at some point in the future, you are just creating a new pointer, pointing to a different commit.

TL;DR: Yes, you can do this, and no, it will not confuse Git.

like image 136
Jeen Broekstra Avatar answered Sep 30 '22 03:09

Jeen Broekstra


Yes, no problem. Branch names are only for humans anyway. Git only cares about SHAs.

like image 21
dualmon Avatar answered Sep 30 '22 03:09

dualmon


You may reuse the branch name at any time, and git won't care.

You could easily confuse yourself though, so you should be somewhat careful here. (I speak from experience :-) )

There's one other consideration: when you share work with other people by publishing commits from your repository or obtaining commits from theirs, you will generally do this by giving them your branch names, or looking at their branch names. If you told Fred to look at your branch foobar last week, and then you deleted foobar and created a new and different foobar this week and Fred goes and gets your foobar, you are likely to confuse Fred, too.

like image 20
torek Avatar answered Sep 30 '22 05:09

torek