Reputation: 45
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
.
Upvotes: 3
Views: 9351
Reputation: 17316
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
Upvotes: 3