8

I'm working on a freelance project. The client (let's call him foobar) asked me to upload the code using his github account (my work PC runs 64-bit Windows 10, I have git 2.15.0) installed.

So I did these steps.

  1. Go to Credential Manager -> Windows Credential -> Generic Credentials. Removed my Github account

  2. On the source code directory, performed the standard procedure:

    git init
    git add *
    git commit -m "first message"
    git remote add origin https://github.com/foobar/supersecretproject.git
    git push -u origin master
    

A Github credential dialog appeared. Entered his credential.

Wait for a while, and yes the code was commited to Github. Opended the Github page, and strangely the commiter shown was me, not foobar. Strange. How to fix this? I want to commit as foobar.

Ken White
  • 123,280
  • 14
  • 225
  • 444
anta40
  • 6,511
  • 7
  • 46
  • 73
  • Possible duplicate of [Change the author and committer name and e-mail of multiple commits in Git](https://stackoverflow.com/questions/750172/change-the-author-and-committer-name-and-e-mail-of-multiple-commits-in-git) – 1615903 Dec 21 '17 at 06:16

3 Answers3

17

If you only want to create a single commit on behalf of someone else and do not want to edit your config, you can also specify the --author argument instead:

git commit --author "Elon Musk <elonmusk@tesla.com>"

This will only set the author metadata of the commit, not the committer metadata about yourself. However, I would even consider this idiomatic as while the correct authorship is maintained, tracing the back the commit to you in case of any troubles is still possible.

Found here.

Christoph Thiede
  • 707
  • 10
  • 16
  • 1
    Worth checking, difference between Author and Committer: https://stackoverflow.com/questions/18750808/difference-between-author-and-committer-in-git – Xarvalus Feb 18 '22 at 20:29
7

If you wish to change config settings for just one repo. You can try this procedure:

1) On the terminal, change the current working directory to the local repository where you want to configure the name and email that is associated with your Git commits.

2) $ git config user.name "Elon Musk". 

3) $ git config user.email "elonmusk@tesla.com"

3) Confirm that you have set the Git username and email correctly:

 $ git config user.name

> Elon Musk

 $ git config user.email

> elonmusk@tesla.com

It's done!:)

Hope this might help!

Vikas Yadav
  • 3,094
  • 2
  • 20
  • 21
  • 1
    This sets the user local-only (tied with current repository), notice there is NOT used '--global' flag, so the global account will remain as it was. Adding this comment as I didn't notice the difference :) – Xarvalus Feb 18 '22 at 20:50
1

You also need to configure your name and email for git:

git config --global user.email "you@example.com"
git config --global user.name "Your Name"
Sergo Pasoevi
  • 2,833
  • 3
  • 27
  • 41