Reputation: 9627
I have created the ssh key and added it to my gitlab account.
Then, I've made a commit:
git add .
git commit -m "w"
git push origin master
But as you can see my username when I committed was root
(this is because user on my laptop is root
1)How do I set the desired username let's call it batman
, so instead of root I want batman to be displayed as commit author?
2)Can I do this using only gitlab interface and without messing with my git config on my laptop? (I am asking because I have several git accounts and I need to use different accoounts for my projects)
Upvotes: 5
Views: 4753
Reputation: 142074
How do I set the desired username let's call it batman, so instead of root I want batman to be displayed as commit author?
# Set the username for git commit
git config --global user.name "<your name>"
# Set the emailfor git commit
git config --global user.email "<your email address>"
... I need to use different accounts for my projects
# --local is the default so you don't have to add it
# Set the username for git commit
git config --local user.name="<your name>"
# Set the emailfor git commit
git config --local user.email="<your email address>"
git filter-branch -f --env-filter '
GIT_AUTHOR_NAME="Newname"
GIT_AUTHOR_EMAIL="newemail"
GIT_COMMITTER_NAME="Newname"
GIT_COMMITTER_EMAIL="newemail"
' HEAD
# Update the username and email as explained above
# Re-commit to update the username/email
git commit --amend --no-edit
Upvotes: 7
Reputation: 11595
In git, commit authoring is defined by the options user.name
and user.email
. Please follow this documentation to set them: https://help.github.com/en/github/using-git/setting-your-username-in-git (it doesn't depends on using GitHub or GitLab).
GitLab/GitHub will use the committer email to link commit author to GitHub/GitLab account.
SSH or HTTP authentication is only used to check permission to push and have no correlation with commit authoring (unlike centralized VCS like CVS or SVN). So you this implies 2 things:
To deal with multiple committer names/emails, better is to define the settings at cloned repository level, or "local", by using the --local
option with git config
.
To change it afterwards, you need to rewrite history while changing authoring and there are already a lot of information on that on SO.
Upvotes: 1