0

I have many repositories with the remote origin set to HTTPS. Now I want to change all origin remotes to SSH.

I am using a command for this in which I want to replace all preceeding url = https://gitlab.mypath/ with git@gitlab.maypath:.

Is there a way to express this with one sed call. Something like:

's@https://gitlab.mypath/@git@gitlab.mypath:@g'

I have to be able to escape the first "@g"

John Kugelman
  • 349,597
  • 67
  • 533
  • 578
sunshine
  • 31
  • 7
  • 3
    Switch from `s@@@` to `s|||`? – Cyrus Feb 14 '22 at 16:03
  • @Cyrus Do you mean s| h t t p s ://gitlab.bla/|@git@gitlab.bla:|g – sunshine Feb 14 '22 at 16:11
  • @Cyrus This was the solution. I am very excited and thank you a lot. This saves me so much time and I also learned something. Woaw. – sunshine Feb 14 '22 at 16:16
  • sunshine, you can post an answer and [self-accept](https://stackoverflow.com/help/self-answer) it after 48 hours. That's the preferred way to mark a question as solved when nobody else has posted an answer. – John Kugelman Feb 14 '22 at 16:29
  • @sunshine: The character after the `s` specifies the separator, which must occur three times in your `s` command. – Cyrus Feb 14 '22 at 16:45
  • Apart from choosing any character for the delimiter, you can also escape that character: `\@`. – dan Feb 14 '22 at 17:26
  • @bad_coder Now that I know that, what follows s is a delimiter, yes. But back than I didnot know even that it is a delimiter. This question is answered already and can be closed – sunshine Feb 18 '22 at 19:08

1 Answers1

0

The correct anwers

  1. Switch from s@@@ to s|||
  2. Apart from choosing any character for the delimiter, you can also escape that character: @

The explanation

The character after the s specifies the separator, which must occur three times in your s command.

Thanks

@Cyrus @dan

sunshine
  • 31
  • 7
  • 1
    Please refrain from answering common duplicates. Once you earn enough reputation, you will be able to vote to close; until then, probably concentrate on answering questions which are not obvious FAQs. – tripleee Feb 17 '22 at 14:27