I'm trying to push code using git to my remote server, but I get the error:

fatal: protocol error: bad line length character:

I researched this bug and it turns out my .bashrc file that echos out a welcome screen is causing this error. What I would like to do is determine if this is a git push and to NOT display the welcome screen, or only display the screen when logging into SSH with no directory parameter:

ssh [email protected]:/deployment/bare-git-repo

Here is the relevant lines in .bashrc:

if [ -e ./.doc ]
    cat ./.doc
    pm2 list

Thanks in advance!

2 Answers 2


I don’t think there’s anything specific to git push hooks on the server, that you could use, but you could check whether you’re outputting to a terminal:

if [ -t 1 ] && [ -e ./.doc ]; then
    cat ./.doc
    pm2 list

This will deal with a number of other cases where outputting the contents ./.doc doesn’t serve much purpose and could cause problems.


I suspect what you really want to do, is prevent running things which have no business being run in a non-interactive shell from running.

A common tactic for this, is to check whether stdin is not attached to a terminal via [[ ! -t 1 ]], or to check whether the bash process is not marked as interactive via [[ $- != *i* ]]. If one of these failure cases evaluates to true, then nothing else in your bashrc should get executed at all, and you should just return early.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .