0

I have two accounts on GitHub. One for a work purpose and one is personal.

Currently I work on personal project but all the code I write in PyCharm has working account name as Code Author.

I searched for a while regarding this topic but still confused is this indicator is PyCharm or Git related function.

What I have done:

  1. Add my personal account in PyCharm --> Version Control --> GitHub
  2. Changed "username" and "email" in git config and git config --global as well.

But nothing works so far. In commits there is a mix of both accounts' name. But last few days commits were applied only from working account. It there something I'm missing?

Antony_K
  • 75
  • 7
  • Try out of Pycharm first. What does it do? It should rely on your git settings (note that you can have different username/email in different folders if you want to). Then if it works with pure git, there's something wrong with Pycharm. – Gaël J Apr 15 '23 at 17:51

2 Answers2

2

The PyCharm "Commit and push changes to Git repository" documentation confirms PyCharm will set the author name/email from the git config user.anem/email settings.

In your case, to be on the safe side, set up your authorship information in the local repository itself:

cd /path/to/repo
git config user.name PersonalAccountName
git config user.email PersonalAccount@Email.com

But another approach is to use only a global Git configuration, but using an includeIf directive, as in blami's answer.

[user]
        name = PersonalAccountName
        email = PersonalAccount@Email.com

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

That way, any repository under ~/repos/work would include the global config ~/repos/work/.gitconfig, which would set your work authorship.

This is valid for any new commit you will create.


For past commits (already created), see How to switch GitHub account and retrospectively update commit history? for an example, using git filter-repo (with a mailmap map), or git filter-repo --commit-callback.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • Thank You for a good advice. After performing changes You've adviced nothing has changed. But looks like GIT (or PyCharm) requires to close a commit first to apply a changes. – Antony_K Apr 16 '23 at 10:46
  • @Antony_K This is indeed for new commits. To change authorship on past commits, see [my past answer](https://stackoverflow.com/a/62145777/6309). I have edited the answer accordingly. – VonC Apr 16 '23 at 18:23
0

Finally solution seems to be in commiting changes prior to making any changes in username/email. I might be wrong, but in my case once I've commited all the changes and make new entries to the project the Code Author name has changed in PyCharm. Not sure if this is a common behavior for a GIT(or PyCharm) but in my case it solve the problem.

Antony_K
  • 75
  • 7