In git there is a command to store the address of the repository under some short name:

 git remote add origin https://thisisanexample.git 

There is also a command to change the repository address:

 git remote set-url origin https://thisistheexample.git 

But which command should be entered so that when you write the repository address to a name, the address by that name changes if it (the name) already exists and is created if it was not?

  • just enter these two commands one by one. - aleksandr barakin
  • Will not work. If the name origin already exists, an error will occur when trying to make git remote add origin ... - faoxis
  • 2
    so ignore the error, and (quote) type these two commands one after the other. and you will have exactly what is stated in the question. - aleksandr barakin

1 answer 1

But which command should be entered so that when you write the repository address to a name, the address by that name changes if it (the name) already exists and is created if it was not?

for example, such:

 $ git remote add имя url-Ρ…Ρ€Π°Π½ΠΈΠ»ΠΈΡ‰Π° || git remote set-url имя url-Ρ…Ρ€Π°Π½ΠΈΠ»ΠΈΡ‰Π° 

it uses the posix-compatible shell control operator || :

 $ ΠΊΠΎΠΌΠ°Π½Π΄Π°1 || ΠΊΠΎΠΌΠ°Π½Π΄Π°2 

ΠΊΠΎΠΌΠ°Π½Π΄Π°2 will be executed only if ΠΊΠΎΠΌΠ°Π½Π΄Π°1 ends with a non-zero return code (i.e., with an error).