PricingSign inDownload

Blog / git

Fix the author on a coding agent's commits

An agent committed as 'agent <agent@localhost>' or someone else. Fix the last commit or a whole branch, find where the name came from, or map it in history.

On this page
  1. See who the commits say wrote them
  2. Find where the agent's name came from
  3. Fix the last commit
  4. Fix every commit on the branch
  5. Credit the agent, on purpose
  6. Fix pushed history without rewriting it
  7. Set the right identity once
  8. Check before you push
  9. Where Joxo fits
  10. Frequently asked questions
  11. How do I change the author of my last git commit?
  12. How do I change the author of several commits?
  13. Why does my coding agent commit with the wrong name?
  14. Can I fix commit authors without rewriting history?
  15. Try it with your team

You open the log and the agent's commits aren't yours: a made-up name, a localhost email, or the identity of whoever set up the machine. Your host may not link them to your account, and the history says the wrong person wrote them. We ran every command with git 2.43 on a scratch repository.

See who the commits say wrote them#

bash
git log --format="%h %an <%ae> %s"
d277605 agent <agent@localhost> Fix typo
4fab0a4 agent <agent@localhost> Test the login form
5214349 agent <agent@localhost> Add login form
9b819a8 Sam Lee <sam@example.com> Initial commit

%an and %ae are the author's name and email. Swap in %cn and %ce to see the committer, which can differ.

Find where the agent's name came from#

Git takes the identity from the GIT_AUTHOR_NAME and GIT_AUTHOR_EMAIL environment variables first, then from user.name and user.email in its config. Check both:

bash
env | grep '^GIT_'
git config --show-origin --get-all user.email
file:.git/config	sam@example.com

--show-origin names the file each value comes from, so you can see if a global or repository setting is the wrong one. If an environment variable shows up, it wins over all of them: look for it in the agent's settings, a wrapper script, or the container it runs in. Fix the source first, or the next commit will be wrong again.

Fix the last commit#

With your own name in user.name and user.email:

bash
git commit --amend --no-edit --reset-author
[main 7a8efbf] Fix typo
 1 file changed, 1 insertion(+)

--reset-author sets both author and committer to your configured identity, and the author date to now. --no-edit keeps the message.

Fix every commit on the branch#

Rewrite each commit the same way with a rebase. HEAD~3 covers the last three; use main to cover everything since the branch left main:

bash
git rebase -r --exec "git commit --amend --no-edit --reset-author" HEAD~3
Successfully rebased and updated refs/heads/main.
bash
git log --format="%h %an <%ae> %s"
3e7b13d Sam Lee <sam@example.com> Fix typo
55eb26f Sam Lee <sam@example.com> Test the login form
850433a Sam Lee <sam@example.com> Add login form
9b819a8 Sam Lee <sam@example.com> Initial commit

Every commit gets a new hash. On a branch only you and your agent use, push with git push --force-with-lease. If it's on a shared branch or main already, don't rewrite it; use the mailmap below.

Credit the agent, on purpose#

If you want the log to show which commits the agent wrote, give it a clear name rather than a broken one:

bash
git commit --amend --no-edit --author="Claude Code <claude@example.com>"

The author becomes the agent and the committer stays you, so the log shows both: who wrote it and who let it in. For new commits, start the agent with GIT_AUTHOR_NAME and GIT_AUTHOR_EMAIL set to that name (see which coding agent made this commit).

Fix pushed history without rewriting it#

A .mailmap file at the root of the repository tells git to show one identity as another. One line per mapping, the right name first:

Sam Lee <sam@example.com> agent <agent@localhost>
bash
git log --format="%h %aN <%aE> %s"
8526fc3 Sam Lee <sam@example.com> Add login form
a9fd9fc Sam Lee <sam@example.com> Initial commit

The capital %aN and %aE apply the mailmap, and git shortlog and git blame use it too. The commits themselves don't change, so nobody has to pull a rewritten branch. Commit the file so everyone sees the same names.

Set the right identity once#

The lasting fix is to give git your identity where the agent will pick it up. For one project, set it in that repository only:

bash
git config user.name "Sam Lee"
git config user.email sam@example.com

Without --global, this goes into .git/config and applies to every commit in that clone, whoever runs git commit, the agent included. A fresh clone needs it again; worktrees of the same clone share it.

If you keep work and personal projects in different folders, let git choose by folder. In ~/.gitconfig:

[includeIf "gitdir:~/work/"]
	path = ~/.gitconfig-work

and put the [user] section with your work email in ~/.gitconfig-work. Any repository under ~/work/ then reports that email:

bash
git config user.email
sam@work.example.com

An agent running in a container or a cloud machine has its own home folder, so your ~/.gitconfig isn't there. Set the identity in the repository, or pass the two environment variables when you start it.

Check before you push#

A one-line check shows every author email on the commits you're about to push:

bash
git log --format='%ae' origin/main..HEAD | sort -u
sam@example.com

One line with your own email means the branch is clean. Anything else, fix it with the rebase above before it leaves your machine, while rewriting is still cheap.

Where Joxo fits#

When several people each run an agent on one project, it matters whose agent did what. Joxo tracks each agent's work as a task under its person's name on a shared board, so you can tell who asked for a change without reading commit authors. Setup is one line pasted into your agent.

Frequently asked questions#

How do I change the author of my last git commit?#

Set user.name and user.email to the right identity, then run git commit --amend --no-edit --reset-author. To set a specific author instead, use --author="Name <email>".

How do I change the author of several commits?#

Run git rebase -r --exec "git commit --amend --no-edit --reset-author" main to rewrite every commit since main with your configured identity, then push with git push --force-with-lease.

Why does my coding agent commit with the wrong name?#

Git uses GIT_AUTHOR_NAME and GIT_AUTHOR_EMAIL from the environment before user.name and user.email from config. Check env and git config --show-origin to find which one the agent picked up.

Can I fix commit authors without rewriting history?#

Yes. Add a .mailmap file mapping the wrong identity to the right one. git log with %aN, git shortlog and git blame then show the corrected name.