Git: Reset author of last commit
- One minute read - 211 wordsTips & tricks …
… and sometimes “things I always have to look up how to do”
I always seems to fall into this and I always have to look up how to fix it. Very annoying. If you have multiple Git credentials and simply clone a repo without specifying any particular credentials, it will use your global default credentials. You can view them with:
git config list --global
For me this is my employer credentials. However, I also have personal credentials and often credentials for my current client project.
This never seems to stick in my brain, so I happily make some changes, commit and push. The push then fails with an “access denied” error.
The trick in this scenario is to change the author in the local Git config for the repo:
git config --local user.name "Your Name"
git config --local user.email "your.name@email.com"
and then reset the author on your last commit:
git commit --amend --reset-author --no-edit
You can view the changes to the local Git config with:
git config list --local
And your commit author info will have been changed as well.
This works for the last commit only. If you have more commits then you are into interactive rebase territory and that is a whole other story…