If you install a new machine and forget to set your email and commiter name, then your Git history will be a tad ugly, with your machine name involved instead of a real email.

So how do you set the default? Like this:

git config --global user.name "Alice E"
git config --global user.email "alice@example.org"

Override per repo

Ideally, do it before you start committing things.

But what if you want different committer names and emails depending on the context? You could set up different user accounts on your machine, macOS, Windows and Linux can all do that. And perhaps that’s a good idea generally, so that your computer environment is contextualized to your chosen persona whether “Dayjob” or “Consulting for A” or “Sideproject”.

The more KiSS approach to get your Git persona straight on a per repo basis, is to just drop the --global from the command above and do an override within each repo. In a way that’s very handy: you know that this working directory, this clone, will always use the same persona regardless of the machine configuration. And it doesn’t propagate if you push the code, only if you copy the entire directory, for example when backing it up with Time Machine

git config user.name "Bob F"
git config user.email "bob@example.com"

One-shot

What if you just need one commit in the name of another author? Simple. But a bit tedious to type if you wanted to do it over and over.

git commit --author="Allie Alias <allie@example.net>"

Retroactive fix

If you discover that your last commit ended up with the wrong author name, you can amend it. Amend is very common when adjusting the commit message or adding more code to the last commit, but it works for author too:

git commit --amend --author="Allie Alias <allie@example.net>"

Adjusting things deeper in the history

What if you need to change more than the topmost commit? Thats a whole topic of its own, but you probably want to use rebase. Often in the interactive form, rebase -i . It comes with dangers of its own: if you rebase a supposedly stable branch that other people depend on, then things will get messy quickly. And rebase is a quick path to losing data if you don’t pay attention. But it is also super powerful.

Rebase allows you to jump to different points in the history of your branch and apply changes, for example with amend.




sponsor

Need private photo sharing that's not tied up in the social media circus? Photoroll is a good way to share photos with your clients.
Or privately gather media from participants of weddings and other small to medium-sized events.