How to change the names and emails of authors and comitters in the git history?
git
Software and digital electronics / Coding
2024-10-25 17:31
I have a code which I have committed with my old email and local name. Now, I need to push my code on a remote server and I want to update the name and email. How is this possible?
add comment
Answered by robin
2024-10-27 13:56
The way to rewrite the git history author and committer information is via git filter-branch as follows
git filter-branch --env-filter '
if [ "$GIT_COMMITTER_EMAIL" = "old-email@example.com" ]; then
    export GIT_COMMITTER_NAME="New Name"
    export GIT_COMMITTER_EMAIL="new-email@example.com"
fi
if [ "$GIT_AUTHOR_EMAIL" = "old-email@example.com" ]; then
    export GIT_AUTHOR_NAME="New Name"
    export GIT_AUTHOR_EMAIL="new-email@example.com"
fi
' -- --all
add comment