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

女生的网名这么多〃 提交于 2019-11-26 22:27:49
Argilium

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.

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

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.

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.

Another possibility is that you misspelled the repository name.

I've done it twice in the last two days. I added a remote and misspelled it and I misspelled the name when creating the project on GitLab.

In both cases when I tried to push to remote I got

fatal: protocol error: bad line length character: No s

So check that spelling!

Also, if you create the project under a different name (like a group) make sure that's the remote you add.

Borja Aparicio

You can get the actual error message by doing:

ssh git@yourgitlabserver.com "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.

I experienced this error message today ("No s"), and it actually had to do with me having no rights to push to the targeted repository. Even though the error message is very weird, this might help people continue to work.

We use Gitlab.

mytydev
sudo gitlab-ctl reconfigure

and then

sudo gitlab-ctl restart

should do the trick

In my case (private key over ~/.ssh/config) I had to leave out the ssh part in:

git clone ssh://git@hostname:username/repository.git

It worked with:

git clone git@hostname:username/repository.git

Error message was:

fatal: protocol error: bad line length character: No s

In my case, my username was changed and this repository's git config was not updated to match the new name.

Check your git remotes to make sure they are pointing to correct place:

git remote -v

Update the config by editing the config manually:

vim .git/config

or through commands

git remote set-url origin https://github.com/USERNAME/OTHERREPOSITORY.git

Adding my experience to this already long list of possible solutions.

In my case I had the access to the repo I cloned, but no access to some other internal repos the package.json was referring to as dependencies or devDependencies. So the solution was getting access to these repos as well.

I had this same issue and turned out that I was working on a git branch. All I needed to do was push to the master.

$ git push <remote> <local branch name>:<remote branch to push into>

change the shell of git

usermod -s /usr/bin/git-shell git
sebastianr

Just adding a possible solution to others in my situation. In my case I was trying to push a tag.

git push heroku MYTAG:master

It wasn't until I dereferenced the tag that it worked

git push heroku MYTAG^{}:master

You can read more about it here: What does ^{} mean in git?

<rev>^{}, e.g. v0.99.8^{}

A suffix ^ followed by an empty brace pair means the object could be a tag, and dereference the tag recursively until a non-tag object is found.

The solution for me was to unset the GIT_SSH env variable which was pointing to putty (plink.exe)

Had the same issue, in my case the origin repo had been moved, changing .git/config solved my problem.

HoGiggle

When I wanted to push my commits, I got this error:

fatal: protocol error: bad line length character: No s

I solved this just by a ssh connection check:

ssh Git@hostIp
Stephanie

My error was: fatal: protocol error: bad line length character: No s

This was caused because I forgot to specify the SCM-tag in the pom.xml of my Maven-project, so it used the SCM-information from the parent project instead. I also had to add our Jenkins user to the project in GitLab.

In my case that error was fixed by changing remote git-user shell to git-shell using chsh:

chsh -s $(command -v git-shell) git

Official git-shell documentation. For security reasons it is highly recommended to use this shell for git-user on remote repository server.

In my case I was observing this error only in "SSH Extensions" for Windows.

The same command worked from command line. I switched SSH setting from PuTTY to OpenSSH and it stopped generating error.

My solution on Windows was switching the connection to SSH in .git/config:

[remote "origin"] url = git@github.com:

As described here:

https://help.github.com/en/articles/changing-a-remotes-url

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!