How do I push to my GitHub repository, with a different user name, but for only one project?

Viewed 90

I have a GitHub repository for my university project. (I have a specific global user name which is not match my real name.) I don't want to change my GitHub user name, and my global git settings. For that project, I want to push an alternative user name, and only for a specific university project.

So if I see the git commits on every branch I want to see that John Doe<JohnDoe@uni.com> committed not john1819 like my other projects.

I have already tried other solutions from Stack Overflow like:

$ git config user.name John Doe
$ git config user.email JohnDoe@uni.com**

This is not a good solution for me,

$ git config --global user.name "John Doe"
$ git config --global user.email JohnDoe@uni.com

I think because it changes the global config.

1 Answers

You can change the configuration locally, just for the current project you're working on:

  1. Open the Terminal inside the root folder of your university project.

  2. Execute the command git config --local user.name "John Doe"

  3. Execute the command git config --local user.email "JohnDoe@uni.com"

Explanation: the flag --local will change the config only for the project in which you are. The global configuration will remain unchanged.

According to Atlassian, you don't need to add the --local flag, because the changes to git configuration are local by default.

Related