Chance
Chance

Reputation: 2700

In git, are there any issues with naming a branch after a commit id?

I run into a detached head state often. I would like to create a script that, when I run, automatically creates a branch where I am at and names it after the current commit id. It appears that git will let me do it, but could a branch and commit having the same name lead to any possible ambiguity or side effects with any git commands?

Upvotes: 0

Views: 69

Answers (2)

Philippe
Philippe

Reputation: 31227

As said by others, don't give an understandable name to a branch is a bad idea and with doing that, you are taking a bad way...

That said, perhaps you could think about creating an alias to create a branch on the current commit, for example:

git b my_new_branch

And to create it:

git config --global alias.b 'checkout -b'

More information here

Upvotes: 2

Caleb
Caleb

Reputation: 125037

It appears that git will let me do it, but could a branch and commit having the same name lead to any possible ambiguity or side effects with any git commands?

If nothing else, it's going to be pretty confusing for you. You could always construct a name for the branch that includes the commit hash but is still easy to distinguish from an actual hash, like Branch_6ac738f999. Using the actual hash by itself seems like a poor plan.

Upvotes: 5

Related Questions