When I run the following on a mac from the command line it works fine:
git submodule foreach "git checkout develop; git pull"
... but when I run it from within a .sh script it gives a git: command not found error:
/usr/local/Cellar/git/2.14.2/libexec/git-core/git-submodule: line 355: “git: command not found
The full script is as follows. The checkout and pull work, but submodule foreach throws the error:
#!/bin/bash
set -e
set -u
git checkout develop && git pull
git submodule foreach “git checkout develop; git pull”
exit 0
Advice I've found says to make sure usr/bin is in my path. But here's what I see when I do echo $PATH (seems to already be there):
/Users/myusername/.nvm/versions/node/v8.0.0/bin:/usr/local/sbin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin:/Applications/VMware Fusion.app/Contents/Public
Your quotes are off.
It should be "git checkout develop; git pull" instead of “git checkout develop; git pull”.
Related
I've created a Python "automation" task that will initialize a repository on github and then on my bash function I'll be creating a folder, initialize the repository as the code bellow shows:
#!/usr/bin/env sh
function repo() {
cd
python C:/Users/wsm/PycharmProjects/GitAutomation/create.py $1
cd C:/Users/wsm/$1
start .
git init
git remote add origin <mygithublink>/$1.git
touch README.md
git add .
git commit -m "Initial commit"
git push -u origin master
code .
}
The only problem is that I have to use source command everytime I close a git bash to enable the command repo (Name of the function) again. Any ideas on how to make that command permanent on Windows 10?
I want to create a bash script to clone repositories and use git checkout. I'm using 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
I want to have all the repositories cloned using the branch Development. But I have the next error:
> $ ./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
You might want to change the variable name that you're using. $PATH is an environment variable and us used to determine which directories are searched when looking for a particular program or executable.
https://en.wikipedia.org/wiki/PATH_(variable)
It looks like setting PATH at the top is preventing bash from being able to find the git binary. Try this instead.
#!/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
As #tkausl mentioned, creating a variable named $PATH in bad, it overwrote the existing one, making the git executable unfindable.
Rename the variable and it should work:
> 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
And here with a different variable:
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'.
I have following list of commands that I run in respective order so that a source project can be committed and pushed to the repository on Bitbucket:
git init
git remote add origin https://[BitBucket Username]#bitbucket.org/[BitBucket Username]/[BitBucket Repository Name].git
git config user.name "[BitBucket Username]"
git config user.email "[BitBucket Email ID]"
## if email doesn't work then use below ##
git config --global user.email \<\>
git add *
git commit -m "[Comment]"
git push -u origin master
Now instead of putting each and every line at their respective time and order, I want to know, if there is a possibility that I can chain all these into single git command and maintain the same order, something like below ?
git init remote add origin https://[BitBucket Username]#bitbucket.org/[BitBucket Username]/[BitBucket Repository Name].git config user.name "[Username]" ....
Or atleast combine multiple same category params like below ?
git config user.name "[BitBucket Username]" user.email "[BitBucket Email ID]"
I need to know possibility of both scenarios with examples.
We can use list off command in single command for example:
git add . && git commit -m "updated pom file" && git push
or:
git stash pop && git add . && git commit -m "updated pom file" && git push
&& -> if 1st command successfully executes then execute next command else it won't execute next command.
& - it executes all the command
|| - execute next command if 1st one failed
If you are in a Windows Powershell:
git add . ; git commit -m "Testing one line command" ; git push
I have gitbash on Windows system and I am not as good with Win batch as with Linux shell.
You still can write a bash script (interpreted by the msys2 bash embedded with Git for Windows).
As mentioned in the comments by Lasse V. Karlsen, and as I mentioned before in "Which shell used for git '!' aliases?", you can write a shell script in a file (in your %PATH%) named git-xxx, and call it with git xxx.
That script would begin with:
#!/bin/bash
I created a file called reset.txt and in that file I have the commands
git reset --hard
git clean -d -f
[this is a newline - very important to have it]
I just copy and paste this into my terminal and it executes the commands in order.
I would like to add new command on my Git Bash (just now i am under Windows OS). I tryed to look on Web different solutions but I did not find anything. The command that i like to add is:
commitall -> git add --all && git commit -m "$*"
There is a way to add this command on Windows Git Bash?
Thanks
Use Git aliases, like so:
git config --global alias.commitall '!git add --all && git commit -m'
There's no need to use $* because all the arguments you specify will simply be appended to the line above, i.e. if you run:
git comitall "a message"
…the following will be executed:
git add --all && git commit -m "a message"
I have a following .bashrc file:
function lazygit() {
git add --all :/
git commit -a -m "$1"
git push
}
function bak() {
git pull
git add --all :/
git commit -a -m "backup: $1"
git push
}
But whenever I call lazygit or bak command, I get:
/home/bok/.bashrc: line 1: lias: command not found
Already up-to-date.
On branch master
Your branch is up-to-date with 'origin/master'.
nothing to commit, working directory clean
/home/bok/.bashrc: line 1: lias: command not found
Everything up-to-date
Why do I get "lias: command not found"?
Open /home/bok/.bashrc and goto line #1. You will see lias and change to alias (the a was probably accidentally deleted).
Close your terminal completely and re-open it. It should work fine now.