我想创建一个bash脚本来克隆存储库并使用git checkout。我正在使用Windows。
#!/bin/bash
PATH="C:\Users\Projects"
echo "$PATH"
git clone https://mygitrepository.com $PATH
cd "$PATH\mygitrepository"
git checkout Development
cd ..
git clone https://mygitrepository2.com $PATH
cd "$PATH\mygitrepository2"
git checkout Development
我想使用分支Development克隆所有存储库。但是我有下一个错误:
> $ ./Clone_Repositories.sh C:\Users\\Projects ./Clone_Repositories.sh:
> line 5: git: command not found ./Clone_Repositories.sh: line 7: cd:
> mygitrepository: No such file or directory ./Clone_Repositories.sh:
> line 9: git: command not found ./Clone_Repositories.sh: line 13: git:
> command not found ./Clone_Repositories.sh: line 15: git: command not
> found
答案 0 :(得分:3)
您可能想更改您正在使用的变量名。 $PATH
是一个环境变量,用于确定在查找特定程序或可执行文件时要搜索的目录。
https://en.wikipedia.org/wiki/PATH_(variable)
在顶部设置PATH似乎使bash无法找到git
二进制文件。试试这个吧。
#!/bin/bash
MY_PATH="C:\Users\Projects"
echo "$MY_PATH"
cd "$MY_PATH"
git clone https://mygitrepository.com
cd "$MY_PATH\mygitrepository"
git checkout Development
cd "$MY_PATH"
git clone https://mygitrepository2.com
cd "$MY_PATH\mygitrepository2"
git checkout Development
答案 1 :(得分:1)
就像@tkausl所提到的那样,在错误的情况下创建了一个名为$PATH
的变量,它覆盖了现有变量,从而使git
可执行文件变得找不到。
重命名该变量,它应该可以工作:
> cat /tmp/t.sh
#!/bin/bash
PATH="C:\Users\Projects"
echo "$PATH"
git status
ghislain@linux (1): ~/home_conf (master *=) ✔
> /tmp/t.sh
C:\Users\Projects
/tmp/t.sh: line 6: git: command not found
这里有一个不同的变量:
ghislain@linux (1): ~/home_conf (master *=) ✖ (148)
> cat /tmp/t.sh
#!/bin/bash
PROJECTS_PATH="C:\Users\Projects"
echo "$PROJECTS_PATH"
git status
ghislain@linux (1): ~/home_conf (master *=) ✔
> /tmp/t.sh
C:\Users\Projects
On branch master
Your branch is up to date with 'origin/master'.