Jim
Jim

Reputation: 14280

Can you re-use deleted Git branch names?

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?

Upvotes: 8

Views: 4664

Answers (3)

torek
torek

Reputation: 489035

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.

Upvotes: 5

Jeen Broekstra
Jeen Broekstra

Reputation: 22052

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.

Upvotes: 9

dualmon
dualmon

Reputation: 1236

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

Upvotes: 6

Related Questions