39

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)?

modulitos
  • 14,737
  • 16
  • 67
  • 110
mikdiet
  • 9,859
  • 8
  • 59
  • 68
  • 1
    There is also some very strange behaviour in this area. If I try 400 chrs it fails. If I then try 300 it passes. Fair enough. But after the 300 worked I then able to create branches with 400,500,600, etc. chrs. trying to test and determine the limit at the command line revealed this behavior. – Michael Durrant Jun 03 '14 at 12:12

2 Answers2

17

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.

Wander Nauta
  • 18,832
  • 1
  • 45
  • 62
  • 1
    I think *some limit* is useful to know, when [GitHub Flow document encourages to use descriptive names.](https://guides.github.com/introduction/flow/index.html) – Ciantic May 03 '15 at 11:48
  • 12
    GItHub limit branch names to 255 chars. – user2284570 Nov 18 '15 at 01:43
  • @iconoclast : because it’s not documented. – user2284570 Jun 07 '16 at 12:10
  • @user2284570 Where did you see the limit of 255 chars referenced in GitHub's documentation regarding the length of branch names? – mljrg Jan 27 '20 at 15:14
  • @mljrg Git branches are stored as filenames. And as Github uses ext4 to store it user s repositories, the branch name limit is the one of the host filesystem which is 255 characters in the case of ext4. Though I got this knowlwedge through [leaks](https://bounty.github.com/researchers/ytrezq). – user2284570 Jan 28 '20 at 16:24
  • @user2284570 Thanks – mljrg Jan 29 '20 at 15:44
  • 1
    Note: Github's branch name limit is 244 characters because they count `refs/heads/` in the name: ```remote: error: GH005: Sorry, refs longer than 255 bytes are not allowed. remote: ref too long: "refs/heads/Lorem-ipsum-dolor-sit-amet-consectetur-adipiscing-elit-Sed-faucibus-et-orci-nec-suscipit-Donec-a-porttitor-sem-porta-laoreet-arcu-Donec-commodo-imperdiet-hendrerit-Morbi-dictum-sit-amet-est-eu-pharetra-Proin-dapibus-ligula-sit-amet-elementum-blandit"``` – Lexi Oct 14 '21 at 16:55
-3

Open the Github Powershell, and execute the following command :

git config --system core.longpaths true

Jobin
  • 5,610
  • 5
  • 38
  • 53
Issam Ressani
  • 203
  • 1
  • 4
  • 7
  • 1
    ^--- this is discussed in [this question](https://stackoverflow.com/questions/22575662/filename-too-long-in-git-for-windows). Apparently it's a Windows filename (incl. path) length limitation, and the _longpaths_ thing is a way to avoid it (provided you have the right version of Git client). That question is from 2014, so by now it might be a non-issue. (BTW, somebody there mentioned git had a filename limit of 4096 chars.) At any rate, OP asked about _branch_ name length, not filenames. – Tom Hundt Sep 24 '19 at 17:58