Here is a little example, that you can use. So I’ve simulated this:
[ian@elise test]$ pwd
[ian@elise test]$ ls
test1 test2 test3 test4
so in my test directory I have four projects. Now in each of these, I have a
.git/config file, so we can now search for what we want to change, so:
[ian@elise test]$ grep -ir "gitlab.com/iwalker"
now the .git/config file has
gitlab.com/iwalker and obviously I want to replace the username. Now, what we will also have to worry about is if the username is also used for login:token, so the url could be
https://iwalker:firstname.lastname@example.org/iwalker/test1. So if we just tried to replace iwalker, we would replace too much of it.
So now with the find command, we want to find just .git/config. So:
[ian@elise test]$ find ./ -iname config
so in this instance, I’m not finding other files that I might not want to replace, but you may wish to filter this further by grepping the
.git directory in case it find config elsewhere. Then when we want to replace the text in the files, we combine it:
[ian@elise test]$ for file in `find ./ -iname config | grep ".git"` ; do sed -i 's/gitlab.com\/iwalker/gitlab.com\/mynewname/' $file ; done
the backslash before the slash inbetween gitlab.com and iwalker is needed, because sed uses slashes as separators. Now the results:
[ian@elise test]$ grep -ir "gitlab.com/mynewname"
now you have replaced it in all your config files very quick and easily. Obviously be careful with sed, and filtering and be sure that the command does what is intended.