Git push results in fatal: protocol error: bad line length character: This

84,441

Solution 1

If anyone else has this problem, the solution is to change the login shell of the user 'git' (or whatever your user is called) to /bin/bash. This can be done via the command : usermod -s /bin/bash git (Link). The reason for changing the login shell is because the default shell for the git user is /sbin/nologin (or similar, depending on environment), which prevents the git application from logging in as the git user on the git server.

Solution 2

Just for other users reference:

fatal: protocol error: bad line length character: no s
can be a truncated answer for "No such project".

As in my case, this kind of error can be fixed by adding user (even yourself) to the project in gitlab:

https://gitlab.com/username/your_project/project_members

also, ensure your public key is set in your user Profile settings > SSH Key or in Project > Settings > Deploy Keys

https://gitlab.com/profile/keys

Solution 3

Another thing to check is that your .bashrc does not print extra stuff. For example 'echo "hello"' in .bashrc creates the error:

kruus@borg:~/malt$ ssh snake01
Last login: Tue Oct 21 10:44:31 2014 from 138.15.166.103
hello
...
kruus@snake01:/net/snake01/usr/hydra/kruus/malt$ git pull
fatal: protocol error: bad line length character: hell

Note how saying hello caused one hell of a problem.

Removing the 'echo "hello"' from my .bashrc allows git to work as expected again. You may need to ">& /dev/null" to remove output if your .bashrc does more complicated things.

Solution 4

The solution to my issue with this was that I'd forgotten to add in a deploy key for the project (for the user I was trying to deploy as).

Adding a deploy key in https://gitlab/group/project/deploy_keys sorted me out.

Solution 5

You can get the actual error message by doing:

ssh [email protected] "git-upload-pack yournamespace/yourreponame.git"

According to this git documentation git protocol expects at the beginning of each line its size and then the content. Looks like GitLab doesn't do that and sends the error message directly.

Share:
84,441
Admin
Author by

Admin

Updated on January 07, 2021

Comments

  • Admin
    Admin over 3 years

    I am trying to get GitLab working on my server (running CentOS 6.5). I followed the gitlab-receipe to the line, but I just can't get it working. I am able to access the web interface, create new projects but pushing to the master branch returns the following error :

    fatal: protocol error: bad line length character: This
    

    I have done checks on the production environment, here are the results :

    Checking Environment ...
    
    Git configured for git user? ... yes
    
    Checking Environment ... Finished
    
    Checking GitLab Shell ...
    
    GitLab Shell version >= 1.7.9 ? ... OK (1.8.0)
    Repo base directory exists? ... yes
    Repo base directory is a symlink? ... no
    Repo base owned by git:git? ... yes
    Repo base access is drwxrws---? ... yes
    update hook up-to-date? ... yes
    update hooks in repos are links: ... 
    ASC / Wiki ... repository is empty
    Running /home/git/gitlab-shell/bin/check
    Check GitLab API access: OK
    Check directories and files: 
        /home/git/repositories: OK
        /home/git/.ssh/authorized_keys: OK
    Test redis-cli executable: redis-cli 2.4.10
    Send ping to redis server: PONG
    gitlab-shell self-check successful
    
    Checking GitLab Shell ... Finished
    
    Checking Sidekiq ...
    
    Running? ... yes
    Number of Sidekiq processes ... 1
    
    Checking Sidekiq ... Finished
    
    Checking LDAP ...
    
    LDAP is disabled in config/gitlab.yml
    
    Checking LDAP ... Finished
    
    Checking GitLab ...
    
    Database config exists? ... yes
    Database is SQLite ... no
    All migrations up? ... yes
    GitLab config exists? ... yes
    GitLab config outdated? ... no
    Log directory writable? ... yes
    Tmp directory writable? ... yes
    Init script exists? ... yes
    Init script up-to-date? ... no
      Try fixing it:
      Redownload the init script
      For more information see:
      doc/install/installation.md in section "Install Init Script"
      Please fix the error above and rerun the checks.
    projects have namespace: ... 
    ASC / Wiki ... yes
    Projects have satellites? ... 
    ASC / Wiki ... can't create, repository is empty
    Redis version >= 2.0.0? ... yes
    Your git bin path is "/usr/bin/git"
    Git version >= 1.7.10 ? ... yes (1.8.3)
    
    Checking GitLab ... Finished
    

    For the init script error, the receipt says

    Do not mind about that error if you are sure that you have downloaded the up-to-date

    so as I have downloaded the latest one, I can't really do much about it.

    I've been banging my head for the past week, and can not figure out why this error is occurring, any help would appreciated!!

  • Nav
    Nav about 10 years
    Any solution for Windows? I'm getting this error while using SmartGit
  • QGerome
    QGerome about 9 years
    I had the same because I didn't know it was case-sensitive.
  • craigdfrench
    craigdfrench about 9 years
    This is the exact use case that I experienced... Echo "Hello". Very good! thank you Erik, and thank you google for finding your answer. Never again will I say echo "Hello"!
  • cjukjones
    cjukjones about 9 years
    I got this error because I had set up keys on my host and forgot to enable the key in gitlab. Enabling the key in gitlab fixed it.
  • Joel G Mathew
    Joel G Mathew about 9 years
    This was exactly the problem on my gitlab machine!
  • einverne
    einverne about 9 years
    Just for other users reference: fatal: protocol error: bad line length character: no s can be a truncated answer for "No such project". As in my case, this kind of error can be fixed by adding user (even yourself) to the project in gitlab: gitlab.com/username/your_project/project_members also, ensure your public key is set in your user "Profile settings" > SSH Key or in Project > Settings > Deploy Keys
  • Léo Lam
    Léo Lam about 9 years
    @Nav: This has nothing to do with your client. It is a change to make on the server-side, and as far as I know, GitLab is not available for Windows.
  • Chris Bush
    Chris Bush almost 9 years
    I feel dumb. Another developer came to me with this issue and long story short, I forgot to add him to the group for the project in GitLab. Thanks!
  • byronyasgur
    byronyasgur almost 9 years
    For smartgit I think you need to change [email protected]:username/repo-slug to https://<username>:<password>@bitbucket.org/username/repo-sl‌​ug.git when doing add remote
  • Berit Larsen
    Berit Larsen over 8 years
    The command doesn't return anything that looks alike an error message
  • barbara.post
    barbara.post about 8 years
    Yes I haven't loaded my private key (using pageant)
  • Alexar
    Alexar about 8 years
    haha, same here! What's the workaround? Where to put I/O redirect?
  • Bogie
    Bogie about 8 years
    This is another right answer since I have created the git user with --shell /bin/bash. Probably most people, which are new to Gitlab, will forgot to add the user as the project member.
  • Havok
    Havok over 7 years
    Downvoting, as this is a serious security issue as you will be giving shell access to the server to anyone with an registered SSH key.
  • Havok
    Havok over 7 years
    BTW you should use usermod -s `which git-shell` git
  • uckelman
    uckelman over 7 years
    Holy crap, that is unobvious. Thanks for adding this as an answer.
  • Nick Grealy
    Nick Grealy over 7 years
    This worked for me - and adding the ssh key for pageant.
  • Leonardo Jauregui
    Leonardo Jauregui almost 6 years
    In my case when entering with the user and password through putty I received the message "Shell access is not enabled in this account", enable access by console, and all fantastic