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?
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.
Yes, no problem. Branch names are only for humans anyway. Git only cares about SHAs.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With