22

I would like to change my github account name, I found an option in GitHub account settings.

However, I am concerned about consequences and would like to know what is the best strategy of name change, considering that I have some projects of my own tied to this account.

So far, I came up with this plan:

  1. Change account name in GitHub settings
  2. For each project's local folder in '.git / config' file update remote "origin" url to the new one

Will this work? Should there be any further steps on a computer which holds project sources? What will be the effect of name change on those who cloned or forked my projects on GitHub?

Thank you!

mikhail-t
  • 4,103
  • 7
  • 36
  • 56
  • 2
    What did GitHub say when you contacted them with this support question regarding their product? – Emil Vikström Jun 04 '12 at 22:48
  • They sent this: ---------------------------------------- From: Tekkub (GitHub Staff) Subject: Renaming user account scenario For (2), it's best not to edit the config directly, try this: https://help.github.com/articles/changing-a-remote-s-url Fixing URLs is the only thing you have to worry about with renaming, nothing else changes. ---------------------------------------- Which worked out just fine. The only thing - those who cloned my project locally would need to re-clone or update remotes manually – mikhail-t Jun 20 '12 at 19:18

3 Answers3

15

GitHub has recently changed their username rename system, and now sets up redirects for you.

From What happens when I change my username? on GitHub Help:

On the GitHub side, everything will behave as if your new username had always been your name. All of your repositories will now belong to that new name and the old username will essentially no longer exist. This can take a few minutes to complete after you initiate the change.

Links to your previous profile page, such as https://github.com/previoususername, return a 404 error. We cannot set up a redirect from the old username to the new one for references like @mentions.

However, redirects are setup for all your repositories. Both web and git access to the old location continue to function, and redirect toward the new username.

Nick McCurdy
  • 17,658
  • 5
  • 50
  • 82
14

1.) You have to change all your projects remote addresses. You can see them via:

git remote -v

After that remove the old remote addres:

git remote rm git@github.com:old_account/foo.git

finally add your new remote address:

git remote add origin git@github.com:new_account/foo.git

2.) All your cloned repos will break. There is no URL-redirect or anything similar. You can change your local cloned repos, but others have to point to the new repo addres(like in Step 1)

Note: Github forked repos works without any problem.

Fatih Arslan
  • 16,499
  • 9
  • 54
  • 55
  • 2
    Works good! Also, there is slightly different command to accomplish the same: https://help.github.com/articles/changing-a-remote-s-url – mikhail-t Jun 11 '12 at 18:44
  • @Petros with fork I meant actually "git clone" by other people. But in Github you're right. Because all forks are have different remote origins. Thanks for the notice! I'll change it – Fatih Arslan Nov 30 '12 at 15:25
  • 3
    Note: GitHub now has URL redirects for repositories from renamed users, so your clones will not break. – Nick McCurdy Sep 17 '16 at 21:40
4

I left a script in my ~/bin called git-reremote with the following content:

 #!/bin/sh
old=richoH
new=richo
git remote -v | grep $old | while read name url type; do
    newurl=`echo $url | sed -e "s/$old/$new/"`
    git remote set-url $name $newurl
done

It's a bit of a hack but it works nicely enough, just cd into the git repo and call git reremote (after making sure it's in your $PATH and also that you've fixed the old and new variables.

richo
  • 8,717
  • 3
  • 29
  • 47