Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to replace a string in a git alias

Currently my organization uses ssh instead of https for Bitbucket. So when one does a

git remote get-url origin

It returns something like…

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

git@bitbucket.org:myorg/myrepo.git

I would like to create an alias that replaces the git@bitbucket.org: with https://bitbucket.org/ to show what the https url would be.

Something like

rr = "!f() { ref=$(git remote get-url origin); echo $ref; }; f"

Except where the echo $ref is, it should do the above replacement instead. I just can’t seem to find a good example of doing this sort of string replacement for a git alias function.

>Solution :

replace the : and then the git@

git remote get-url origin|sed 's!:!/!g'| sed 's!^git@!https://!g'
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading