git - How can I, in one command, create or update a remote? -
i don't know whether remote called origin exists. command
git remote add origin gti@gtihub......git throws error
fatal: remote origin exists i need add origin remote if not exists, , update if exists. how can in 1 command?
(for information, use git version 1.7.3.4.)
also, difference between:
git remote add origin gti@gtihub......gitgit remote set-url origin gti@gtihub......gitgit remote set-url --add origin gti@gtihub......git
does 1 of commands want?
[...] difference between [...]
git remote add <name> <url> adds remote named <name> repository @ <url>.
git remote set-url <name> <url> sets url remote called <name> <url>.
git remote set-url --add <name> <url> adds new (push) url remote called <name>; that's not want do.
the first command throws error if remote called <name> exists, whereas last 2 commands throw error if no remote called <name> exist.
refer git-remote man page more details.
i need add remote origin when not exists, , update if exists.
you can use conditional execution that:
git remote add <name> <url> >/dev/null 2>&1 || git remote set-url <name> <url> the second command (git remote set-url ...) run if first 1 (git remote add ...) returns nonzero exit code.
the >/dev/null 2>&1 part redirecting standart output , standard error of first command /dev/null, can think of unix's "bottomless pit"; here introduction output redirection.
for convenience, may want define alias this.
Comments
Post a Comment