0

It is possible to set up two user profiles with git, one for work and one for personal, but since we can also amend the author of a commit by

git commit --amend --author="Author Name <email@address.com>"

can we just use that to modify the author, if we just do lightweight work on the personal account, for example? Is it exactly the same as having two computers or two accounts on a Mac / Unix system with different git profiles?

nonopolarity
  • 146,324
  • 131
  • 460
  • 740
  • Does this answer your question? [How to tell git to use the correct identity (name and email) for a given project?](https://stackoverflow.com/questions/6116548/how-to-tell-git-to-use-the-correct-identity-name-and-email-for-a-given-project) – phd Apr 07 '20 at 10:03
  • https://stackoverflow.com/search?q=%5Bgit%5D+multiple+identities+-ssh – phd Apr 07 '20 at 10:03
  • Git records the auther **and the committer**. Your command changes just the author, but not the committer. So, it is not equivalent. – j6t Apr 07 '20 at 10:41

1 Answers1

1

Amend is a really bad way to change the author for a specific git repo, because once you forget to do this one time it will become a big mess of force pushes etc. The better way to do this is setting user for the current repo. This works with running git config user.name "User Name" and git config user.email "user@example.com" without the --global flag. You can find more information about it here.

jugendhacker
  • 126
  • 7
  • you mean we can set two aliases, one as `alias as_work_person='git config --global user.name "My Name" && git config --global user.email my.work.email@gmail.com' ` and another for personal info, and then once we `cd` into a folder and start working, make sure we use the correct alias to take that identity and start working? I wonder what if accidentally you `cd` into a different folder and commit something – nonopolarity Apr 07 '20 at 14:54
  • but I found that if you have 2 Bash shells, and you use one alias above, then the other shell will change your git identity too, probably due to the `~/.gitconfig` being used to look up who you are every time you commit something – nonopolarity Apr 07 '20 at 15:05
  • @nonopolarity no I did not mean doing it with an alias.... if you do git config without --global it will set the setting just for the repo you are currently cded into, so you could set up an alias make_work_repo with `git config user.name "Work Name" && git config user.email "email@work.com"` and then everytime you clone or init a repo for work just run the alias one time and it will be set for this repo.... – jugendhacker Apr 08 '20 at 15:10
  • ah ok... another way I found was to create another account on the Mac and switch account to it, and later on found that I can actually use `login` in Bash to become that user (and use a different Git profile) – nonopolarity Apr 08 '20 at 15:33