Brock Woolf
Brock Woolf

Reputation: 47292

Amend username for a pushed commit on Github

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?

Upvotes: 33

Views: 22945

Answers (4)

Yisal Khan
Yisal Khan

Reputation: 387

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

Upvotes: 0

stevenspiel
stevenspiel

Reputation: 5999

As noted here, you can do

git commit --amend --author="Author Name <[email protected]>"
git push -f

Upvotes: 32

Cascabel
Cascabel

Reputation: 496722

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.)

Upvotes: 31

Brock Woolf
Brock Woolf

Reputation: 47292

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.

Upvotes: 4

Related Questions