2

I am using Visual Studio 2022 to publish a new repo to Github. I have two Github accounts. Let's say user1 and user2. user1 is my main account. user2 is mainly for testing purposes.

In VS, I use user1 Github account to publish. The repo is now in user1's Github account. However I am surprised to see user1 and user2 as the contributors. Why did Github add user2? How does Github know they are both mine? The two accounts shouldn't be related in any way.

So I go and delete user2 account from Github and repeat everything again. I don't see two contributors anymore but I still see that 'user2 Add project' in the Code web page. Again, why is Github mentioning user2 again? user2 is deleted now.

I do a text search on the repo files on my machine and noticed 'user2' in 3 files under the '.git' folder. A 'HEAD' file and two 'master' files. It seems the culprit is Visual Studio or Git on my machine?

I deleted the .git folder several times and repeated the process. Deleted github cookies from Chrome thinking it's related.

My question is.. Where is Visual Studio or Git picking 'user2' from and why it's using it to publish? It seems it's using user1 to know the target repo but not who published it.

Tony_Henrich
  • 42,411
  • 75
  • 239
  • 374
  • The name/email associated with commits is based on the global/local config. Can you see what the output to `git config user.email` and `git config --global user.email` are (from the repo folder)? If you never messed with terminal `git` and always performed actions through VS, then maybe someone who has used it can suggest some in-program settings. – shriakhilc Jan 28 '22 at 18:35
  • They showed user2. I made the edits. Thanks. – Tony_Henrich Jan 28 '22 at 19:20

1 Answers1

0

They showed user2. I made the edits.

If you have many commits done with the wrong author, you rewrite them with the right one, with newren/git-filter-repo.

See "How to change commit author for multiple commits using filter branch?" and
"git filter-repo / User and email based filtering"

git filter-repo --mailmap my-mailmap

with my-mailmap:

Correct Name <correct@email.com> <old@email.com>

That will rewrite your commits with author1 instead of author2.

Note: You will need to git push --force (assuming one main branch) in order to override the remote history with your new commits: make sure every collaborator clone the repository again, in order to use the new history.

Then you can resume your works/commits from Visual Studio, with the right setting set to the correct value.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250