I want the commit to be displayed as a separate account on GitHub.

Asked 2 years ago, Updated 2 years ago, 124 views

I'd like to demonstrate how multiple accounts commit to one repository of the internal study group, but I don't know how to change users.

I would like to create folder A and folder B on the local side, prepare two GitHub users and assign them to each folder, and make them look like, "Change the local repository of folder A, change the local repository of folder B, and pull it like this~"

However, even if you sign in to GitHub as a different user, the ssh and https that are issued are the same, and both A and B are displayed as commits from users who use them regularly.

How should I do it?
RELATED: How to switch accounts for multiple Gits from the same PC

git github

2022-09-30 21:21

2 Answers

GitHub identifies the "user who created the commit" with the email address used for the When I first used Git, I set it up through some tools and the following commands.

git config --global user.name "Your Name"
git config --global user.email "[email protected]"

For example, above, GitHub displays [email protected] as a commit by a registered user.

Why are my commits linked to the wrong user? - GitHub Help Articles

Therefore, if you want to display it as another GitHub user, change the email address to be used for commitment.In addition, non-GitHub tools and git commands will show the names to be used for commitment, so in the following example, the names have also been changed.

This name appears outside of #GitHub, so you can change it together.
git config user.name "Your Another Name"
git config user.email "[email protected]"

By running without the --global option, you can write the configuration to .git/config in the repository.This way, you can use a specific email address only in that repository.Alternatively, you can open .git/config in a text editor and add the following settings:

 [user]
    name = Your Another Name
    [email protected]

Once configured like this, it will remain after reboot and will be applied when committing with another tool.However, the configuration is stored in the local repository, so if you clone it, you must reconfigure it.

You can also temporarily change the environment variables GIT_AUTHOR_EMAIL and GIT_COMMITTER_EMAIL.If you want to use a different name from time to time, but not always, it may be useful to have commands or scripts to configure them.

export GIT_AUTHOR_NAME="Your Another Name"
export GIT_AUTHOR_EMAIL="[email protected]"
export GIT_COMMITTER_NAME="Your Another Name"
export GIT_COMMITTER_EMAIL="[email protected]"

a Set both author and committer.

Even if you sign in to GitHub as a different user, the ssh and https that are issued are the same

For GitHub

  • SSH has a fixed username, identifies by which key to connect
  • HTTPS specifies a username and password for Basic authentication, but is not included in the URL issued

Therefore, the same URL will be issued regardless of the user at this time.

In fact, however, this is only used to determine if you have access to the repository, or you will be troubled if you set the same SSH key to multiple users.


2022-09-30 21:21

In @unarist's response,

Method 2. Temporarily change with environment variables

Additionally, direnv allows you to use different environment variables for different directories.

In addition, direnv has a feature called source_up, which allows you to climb the directory hierarchy and load additional .envrc.

I often create directories for each organization (mostly using github's (organization) account name), create a repository for git in each organization directory, place .envrc in the organization directory itself, and add GIT_AUTHOR_EMAIL and GIT_COMMIT_EMAIL to each repository environment.


2022-09-30 21:21

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.