Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Max length of git branch name

Tags:

git

github

I want to understand what is maximum allowed size of a git branch name.

I am trying to create some long names (as an experiment) so a name with 370 characters was valid, but 380 characters gave me fatal: Failed to lock ref for update: File name too long

So the questions is: what is the maximum number of characters that can be in git branch name? Does it depend on the system? Is it possible to create long branch name in a repository that will be rejected on remote repository (i.e. Github)?

like image 791
mikdiet Avatar asked Jun 03 '14 11:06

mikdiet


People also ask

How long should branches exist git?

One key rule is the length of life of the branch before it gets merged and deleted. Simply put, the branch should only last a couple of days. Any longer than two days, and there is a risk of the branch becoming a long-lived feature branch (the antithesis of trunk-based development).

What should git branch name be?

Most conventions recommend leading the branch name with prefixes like hotfix- , feature- , chore- , or some other variant of the categorization of tasks. Practically, if you are using an issue tracker, you're tagging the category of the task in the issue tracker anyway — in addition to much more additional context.

Are spaces allowed in git branch names?

Creating a New Branch In Git, the git branch branch-name command is used to create a new branch called branch-name . Branches should be named something that describes the purpose of the branch. Note that branch names can't contain whitespace: new-feature and new_feature are valid branch names, but new feature is not.


1 Answers

The 'File name too long' is indeed an error coming from your system. It is not a restriction in Git. I don't think there's a way of testing the maximum branch name lengths of other systems, like GitHub's, without experimenting - although I don't see why you would want to know...

.

Source: the error mentioned is thrown on line 291 of branch.c. "File name too long" is the standard description for the ENAMETOOLONG error.

like image 178
Wander Nauta Avatar answered Oct 19 '22 20:10

Wander Nauta