33

I made a push to a newly forked git repo on Github but after committing i noticed that my username was incorrect. The username I pushed was "Brock Woolf" but it should have been brockwoolf which is my username on github.

I already changed the default locally like this:

git config --global user.name "brockwoolf"

But how can I change the username on the already pushed change?

Brock Woolf
  • 46,656
  • 50
  • 121
  • 144
  • You can of course do what you like with your projects, but that config parameter is `user.name`, not username, as in "the name of the user." Using real name for it is pretty common. – Cascabel Aug 29 '10 at 13:14
  • I know but for github, you use your username or it won't associate Gravatars i think. – Brock Woolf Aug 29 '10 at 15:30
  • Duplicate of [How do I change the author of a commit in git?](http://stackoverflow.com/questions/750172/how-do-i-change-the-author-of-a-commit-in-git) –  May 18 '14 at 16:30
  • 1
    @BrockWoolf no, the "name" field has no real effect on anything in GitHub; it's the email address that determines your gravatar and identity. – hobbs May 18 '14 at 17:24

4 Answers4

31

The already pushed change, if people have pulled it, is something you'll have to live with. If no one's pulled it (i.e. you realize your mistake right after pushing), you can amend your commit:

git commit --amend

Make sure you don't add any new changes to the commit - don't use -a, don't use git add first. Then you can force the push, since this is a non-fast-forward change:

git push -f

If anyone's already pulled the commit with the incorrect name... this probably won't actually mess them up, since merging it with something containing the original commit should be easy; the patches are the same. However, if that person ever pushed back to your repo, they'd push that merge - along with the original commit on one side of it. Kind of defeats the purpose of renaming yourself if you end up with both names in the repo. (This is exactly the problem I described in my comment on the OP's answer.)

Cascabel
  • 479,068
  • 72
  • 370
  • 318
  • 2
    -f is not in the man page for push. What does the -f do particularly? Something like checkout -f? – Jonathan Dumaine Jan 09 '11 at 21:44
  • @Jonathan: Yes it is. It's in the usage statement as `[ -f | --force ]`, and it's described under both short and long names about ten down in the options section. It does what I suggested in the answer: non-fast-forward pushes are normally rejected, but this forces it to be accepted. – Cascabel Jan 09 '11 at 22:10
  • I retract my question--it's definitely right there. I must be losing my head. Maybe I was looking at the wrong man page haha. – Jonathan Dumaine Jan 09 '11 at 22:12
  • @Jonathan: Haha, all right. I was wondering if you were looking at the v0.99 man page or something. – Cascabel Jan 09 '11 at 22:16
  • @Cascabel, how should I deal with several pushed commits? – tonwayer Jan 17 '23 at 12:16
31

As noted here, you can do

git commit --amend --author="Author Name <email@address.com>"
git push -f
Community
  • 1
  • 1
stevenspiel
  • 5,775
  • 13
  • 60
  • 89
4

Sweet I figured it out:

git commit -a --amend
git pull
git push

Feel free to answer, if you have a better way I'll mark yours correct.

Brock Woolf
  • 46,656
  • 50
  • 121
  • 144
  • 2
    This won't actually change the original commit. The `git pull` fetches the original position of `origin/master`, which is `master@{1}`, the original commit. It then merges it. The merge goes smoothly, because the two sides made exactly the same change; the only difference is the name and date on the commit. Both commits are still there. – Cascabel Aug 29 '10 at 13:14
  • 1
    (And you probably didn't need the `-a`, unless you were committing additional changes as well as changing the name...) – Cascabel Aug 29 '10 at 13:15
  • @Jefromi: Thanks for your comments. Yes i probably didnt need the '-a' switch. – Brock Woolf Aug 29 '10 at 15:28
0

Following is the command to update the Author Name on git after pushing the changes

git commit --amend --author="Author Name <commit-name>"
git push -f
Yisal Khan
  • 359
  • 3
  • 10