I'm jus trying to clean up my code and eliminate errors. If I run:
git remote add godaddy [email protected]:~/root.git
I get
fatal: remote godaddy already exists.
I know it exists, but I just want it to ignore it and create it again.
For example you can suppress errors for mkdir
with the -p
I checked here but could not find anything:
https://git-scm.com/docs/git-remote
This is not a duplicate as I'm looking for a command line option to supress the "error".
You can't tell Git to suppress the error, if it already exists you either need to remove it and re-add it, or update its URL. Suppressing the error for mkdir
is OK, because if it exists you don't need to make it. With a Git remote that's not true, because the existing one might have a different URL, so just ignoring the command isn't OK if it fails.
Assuming this is some script that you are trying to change (otherwise if it's a manual process on the command line then just ignore the error and get on with something more important) there are two simple solutions I can see:
check for the remote first, and either update it or add it, as appropriate:
if git remote | grep -w godaddy ; then
git remote set-url godaddy [email protected]:root.git
else
git remote add godaddy [email protected]:root.git
fi
just try adding it and if that fails then update the URL:
git remote add godaddy [email protected]:root.git || git remote set-url godaddy [email protected]:~/root.git
Another option would be to redirect stderr to /dev/null
and make the command return true even git
exits with an error, but that's probably not a good idea:
git remote add godaddy [email protected]:root.git 2>/dev/null || true
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With