Skip to content

Instantly share code, notes, and snippets.

@whilei
Last active August 5, 2016 23:16
Show Gist options
  • Save whilei/0eef54cfa7d31bedb98a3e6ab09b45c5 to your computer and use it in GitHub Desktop.
Save whilei/0eef54cfa7d31bedb98a3e6ab09b45c5 to your computer and use it in GitHub Desktop.
Shit, I changed by Github username...
# Want to change your Github username?
# Want to change the url of your self-hosted git remote handler (ie Gogs)?...
# This solve is to find every .git/config file (which is where each project-related git configuration lives) and edit
# according to your whims. That's where the `sed...` part comes into the play. `sed s/x/y/g` will substitute all
# x for y globally in the given file. The given file in this case is the `find`ers.
# In the examples, the `-i.bak` part is making a backup just in case which you needn't worry about if shit doesn't hit the fan.
# Note that this given sed parses the git config file globally. Make sure your subsititutions are specific enough.
# Usage example:
# $ find_git_configs some/where "sed -i.bak s/theold/thenew/g"
# En generale...
find_git_configs() {
# $1 is wherein to search for git projects, beit your home directory, your host directory, a projects-based directory... wherever you keep your git shit that you want to chagne
# $2 is what to do upon finding each such git project configuration; should be a shell statement
# (what about the target you ask? i don't know. i'm drunk. the execetuable statement is going to be passsed the file.
# ... for each file do a thing. do things $2. don't ask too many questions and buy me more beers.
find $1 -path "*/.git/config" -exec $2 {} \;
}
# Changed username...
find_git_configs ~/ "sed -i.bak s/irstacks/abettername/g"
# Changes remote base url...
find_git_configs ~/ "sed -i.bak s/dumbname.com/bettername.com/g"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment