Link to home
Start Free TrialLog in
Avatar of userTester
userTesterFlag for United States of America

asked on

Github username

I have a few github accounts, and noticed that when I commit from my computer, I see that the commit is done by my one username, irrespective of which github account I commit to.

So if my usernames were githubUser1, githubUser2, or githubUser3, and I committed to githubUser3, githubUser3's account is showing that the commit was done by githubUser1.

Why, and how do I make sure the githubUser3 shows that the commit is done by githubUser3?
SOLUTION
Avatar of Steve Bink
Steve Bink
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of userTester

ASKER

Thanks Steve, but I've used these commands before, but all it (git config user.name) gives is my name (firstname lastname), but not the actual github username (myUsername).

echo $GIT_COMMITTER_NAME and echo $GIT_AUTHOR_NAME, prints nothing for each of my local git repository.
So you want to change the *credentials* you use to push, not just the cosmetic name of a commit author.  Are you using the git desktop client, or command line?  I'm assuming you are on Windows...

With command line, git will either know to authenticate with a specific SSH key or ask you for credentials each time you push.  A key will be tied to a single user account on github...you can only change that by changing the key the repo uses.  See how to check for existing keys.  Other links on that page will instruct you on generating a new key or replacing an existing one.

I'm not very familiar with the desktop client, but I believe it leverages the same mechanisms behind the scenes.  When you install the GHFW client, part of the initial setup asks for the github account you with to use.  You should be able to use the same instructions from the above link within the git bash console.

The echo commands will only work if you have set those items in your shell - they are local variables that git knows to use if they exist.  Again, though, those only affect the "display" version of the author name, not the credentials used to push the commit.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I have committed using GitBash on a Windows 10 computer.

When I commit and push from my iMAC, it shows one of my other usernames on all GitHub repositories, but only when I commit and push from the iMAC.

So when I work on my Windows PC, it always show a specific username, but on the iMac is shows a different username.
Sorry, to be more clear:

So when I commit and push to githubUser3's Github repository, from my Windows PC, it always shows githubUser1 as the commit author, but on the iMac is shows githubUser2 as the commit author.

Keep in mind that it is supposed to show githubUser3 as the commit author, irrespective of which computer I use, since I have to sign in to  githubUser3 for each push to the Github repository.
Avatar of pepr
pepr

If you use Git program to create the commit on both Windows PC and iMac, and then push the result to any of your github repository, then the name comes from or Windows PC or from iMac...

When you want to have githubUser3 commiter name  on github, the you have to set that name both your Windows PC, and on iMac (it can be local to the project, but it has to be set that way; otherwise Git will use its global settings which is probably not the "githubUser3"). The commit point is created or on your Windows PC, and the name set at Windows PC is used, or it is created on your iMac, and the name from iMac is used. The name is copied into the commit point. When the commit point is pushed to any Git repository, the copied name will appear there.

Think in terms:
- The committer name is given somehow to the "git commit", and it becomes the integral part of the commit point."
- The commit point is the same everywhere it is pushed. It is not repository dependent. It is part of the commit.
- When pushing elsewhere, the commit already exists, and the name is already packed with it. It does not depend on the destination.

Type git config --local user.name to get the local name for the project, git config --global user.name to get the global name for the computer, or git config user.name to get the name that will be used for the next commit.
pepr,

I will change the global username on my PC, and see if my commit / push to Github shows the changed username as the commit author, and get back with the results.
I think we were all fixated on the username, when in actual fact, it was my email address (git config user.email), that is what bound the githubUser1 to each and every Github account, despite logging in as githubUser3, or githubUser2, etc.
With email it is the same as with commiter name. The githubUserX is used mainly when you want to log into your github repository. What I want to say is that the user name for the github is kind of unrelated to the commit -- unless you do the commit through the github page.
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
To add... Each commit can have a different committer. If you want to have different name/e-mail for different projects (say, different for your closed-source project related to your employer, and different for your open-source project related to your other activities), you can set the values locally for the project using git config --local user.name myNameForThisProject and git config --local user.email myEmailForThisProject. The doc says the --local is the default so you can leave it out. The config values should be found in your local .git/config file.
Thanks guys, I appreciate your assistance.

Even though there was some confusion about user.name and username, and your answers did not specifically say that user.email contained the answer, I feel that you guys referred me to links that I found useful.

Steve, your link to setting-your-username-in-git, contained the tip that mattered. This wasn't very clear to me at first:
Tip: You don't have to use your real name--any name works. Git actually associates commits by email address; the username is only used for identification. If you use your email address associated with a GitHub account, we'll use your GitHub username, instead of this name.
pepr, your link GitHub-Account-Setup-and-Configuration, also helped.
Your Email Addresses: The way that GitHub maps your Git commits to your user is by email address.
Links to relevant information can be powerful, but one has to be specific about what to look for, and provide a brief summary that references the relevant information.
I see :) "...  I see that the commit is done by my one username, irrespective of which github account I commit to."

This is a classical confusion. So, you are talking about what GitHub thinks is the author, and I am talking about how the author is stored in the commit object :)

You can also have a look at http://schacon.github.io/gitbook/1_the_git_object_model.html that describes the internals of the commit object and how you can display what is inside the object. Then you may notice the difference between what GitHub thinks about the author name base on the user.email, and what author name or the commiter name (when the person who created the commit point differs from the patch author) the commit object really stores, like
git show -s --pretty=raw badbeef

Open in new window

where badbeef is the prefix of SHA-1 of the commit. Or you can simply use git log to see (on your local computer) both the address and the name stored in the listed commit points.
Thanks guys, I appreciate your assistance.

Even though there was some confusion about user.name and username, and your answers did not specifically say that user.email contained the answer, I feel that you guys referred me to links that I found useful.

Steve, your link to setting-your-username-in-git, contained the tip that mattered. This wasn't very clear to me at first:
Tip: You don't have to use your real name--any name works. Git actually associates commits by email address; the username is only used for identification. If you use your email address associated with a GitHub account, we'll use your GitHub username, instead of this name.

pepr, your link GitHub-Account-Setup-and-Configuration, also helped.
Your Email Addresses: The way that GitHub maps your Git commits to your user is by email address.

Links to relevant information can be powerful, but one has to be specific about what to look for, and provide a brief summary that references the relevant information.