3

I'm trying to update a git repo from a bash script and I've run into some trouble. I can run git pull and have it work if there is no other lines or characters after the git pull but if I say have

#!/bin/bash
git pull
echo "test"

then I get

' is not a git command. See 'git --help'.

Did you mean this?
        pull

in the terminal instead of it actually doing the git pull.

4
  • 11
    Does that file have DOS newlines? Does running dos2unix on that script help? Commented Jul 8, 2014 at 16:39
  • use apt-get install git if you have UNIX based system, install git manually if you have window based system. Commented Jul 8, 2014 at 16:42
  • As @EtanReisner suggested, you make actually be running git pull\r. Commented Jul 8, 2014 at 17:31
  • 3
    @Ioan They clearly have git installed as they are getting an error message from git. Commented Jul 8, 2014 at 17:43

1 Answer 1

3

You have to do dos2unix first like Etan mentioned. I can regenerate the same error if I do the reverse (i.e. unix2dos)

$ cat 1.sh

#!/bin/bash

git pull
echo ----

$ ./1.sh

fatal: Not a git repository (or any parent up to mount parent /cygdrive)
Stopping at filesystem boundary (GIT_DISCOVERY_ACROSS_FILESYSTEM not set).
----

See above, git pull command worked but with a valid error message that no repo mentioned after pull as im doing first time. That means git exists (if you do which git you'll see valid git executable location).

$ unix2dos.exe ./1.sh

unix2dos: converting file ./1.sh to DOS format ...

Now, my file is in DOS format (and Im running the script in Linux machine). Are you using Cygwin?

$ ./1.sh

./1.sh: line 2: $'\r': command not found
' is not a git command. See 'git --help'.

Did you mean this?
        pull
----

OK, convert it back to Unix line ending chars using dos2unix

$ dos2unix.exe ./1.sh

dos2unix: converting file ./1.sh to Unix format ...

$ ./1.sh

fatal: Not a git repository (or any parent up to mount parent /cygdrive)
Stopping at filesystem boundary (GIT_DISCOVERY_ACROSS_FILESYSTEM not set).
----

It works as expected.

OR try running with bash -x

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.