Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Simulate multiple users/committers on local system

Tags:

git

From my book, I am trying to learn how to simulate multiple Git users on my local system itself. I will pretend to be all those multiple users. I followed my book's instructions to simulate multiple users committing changes to a repo. The book output shows two different people when git log is executed. But, my output shows only one user, that is me. How do I make more users so that I can simulate the scenario?

commit aed341198f614860bfb68f5fd5845f191773fa36
Author: sid smith <[email protected]>
Date:   date

    Bobs first commit after changing the first line

commit edabfcc8a432b07f92a564147ee6ebb8865f5d18
Author: sid smith <[email protected]>
Date:   date

    Base commit from source

Is there a web-based Git where I can login (as multiple users) through multiple browsers to simulate multiple commits in Git?

like image 824
sid smith Avatar asked Jun 10 '26 09:06

sid smith


1 Answers

You need to change your user.name and user.email when you commit.

To do so without affecting your git config, you can set environment variables for a specific commits in order to do that commit "as someone else".

GIT_AUTHOR_NAME="anotherName" GIT_AUTHOR_EMAIL="another@email" \
GIT_COMMITTER_NAME="anotherName" GIT_COMMITTER_EMAIL="another@email" \
git commit -m "commit done as another person"

That will apply only for the current commit.
All the others will be done with the user.name and user.email values you see in git config --global --list.

See the section "Environment Variables" of the git manpage for all the variable you can set.

Another way is to override the config on the git command with the -c option of the git command:

git -c user.name="anotherName" -c user.email="another@email" commit -m "..."

(lowercase '-c', not uppercase '-C', which is another option)

That is easier to set as an alias, which in Windows is called doskey:

doskey gituser1=git -c user.name="anotherName" -c user.email="another@email" $*

(the $* is to get all the othe parameters you will pass to that command)

You would use that as:

gituser1 commit -m "commit done as another person"

I get an error

C:\repo>
GIT_AUTHOR_NAME="Bob" GIT_AUTHOR_EMAIL="[email protected]" 
  'GIT_AUTHOR_NAME' is not recognized as an internal or external command, 
  operable program or batch file.

Indeed, Windows shell wouldn't support that syntax directly.

As mentioned in "Setting environment variable for just one command in Windows cmd.exe", you would need to type:

cmd /C "set GIT_AUTHOR_NAME=\"anotherName\" 
&& set GIT_AUTHOR_EMAIL=\"another@email\" 
&& set GIT_COMMITTER_NAME=\"anotherName\" 
&& set GIT_COMMITTER_EMAIL=\"another@email\" 
&& git commit -m \"commit done as another person\""

(one giant line)

NOTE - In windows/cmd, you must remove all the backslashes and the last double quote to make this work.

like image 93
VonC Avatar answered Jun 13 '26 04:06

VonC



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!