Here is a little example, that you can use. So I’ve simulated this:
[ian@elise test]$ pwd
/home/ian/test
[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"
test1/.git/config:gitlab.com/iwalker/test1
test3/.git/config:gitlab.com/iwalker/test3
test2/.git/config:gitlab.com/iwalker/test2
test4/.git/config:gitlab.com/iwalker/test4
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:mytoken@gitlab.com/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
./test1/.git/config
./test3/.git/config
./test2/.git/config
./test4/.git/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"
test1/.git/config:gitlab.com/mynewname/test1
test3/.git/config:gitlab.com/mynewname/test3
test2/.git/config:gitlab.com/mynewname/test2
test4/.git/config:gitlab.com/mynewname/test4
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.