[edit] I wrote my long-ish answer, and then I saw you mentioned gitlab.
By googling "gitlab block author", I landed on this page :
https://docs.gitlab.com/ee/push_rules/push_rules.html#enabling-push-rules
There is a push rule :
Check whether author is a GitLab user
Starter 7.10
Restrict commits by author (email) to existing GitLab users.
See if you can activate that one on your server or account.
If you (or any user) have created locally a commit with the wrong user account, though, you would still have to edit this commit as below before pushing.
First : there are two places where something that looks like a username is mentioned :
- the information stored in a commit (the author of this commit is
blockeduser@email.com
)
- the credentials used to pull/push to a remote (the username in
https://blockeduser@github.com
, or the username associated to the ssh key when going through ssh)
1.
comes from the configuration parameters git config user.name
and git config user.email
,
2.
comes from the urls you use to acces your remote, and some configuration on your system (e.g : ~/.ssh/config
if you use ssh, possibly the credential manager used by git, etc ...).
When you say that the user is "blocked" you probably mean that 2.
wouldn't work anymore if you used this user's credentials.
For 1.
however :
even if blockeduser
is now blocked, it is legitimate to keep the information on past commits which were created/edited by this user as is.
You may take some actions to refuse new commits where blockeduser
is the committer, but most of the time no check is applied on the author/committer of a commit.
The general rule is :
- update
git
's configuration to have the correct author/committer set in new commits you created,
- if you mistakenly created some commits with the other guy's email, you can edit these commits, and
push -f
the result.
To do that, see for example these SO questions :
How to change the commit author for one specific commit? :
git commit --amend --author="Author Name <email@address.com>" --no-edit
How to change the author and committer name and e-mail of multiple commits in Git?
Spot in your history the id of the first commit to rewrite (say: eacf32
) and replace <parent>
below with eacf32^
:
git filter-branch --env-filter '
OLD_EMAIL="your-old-email@example.com"
CORRECT_NAME="Your Correct Name"
CORRECT_EMAIL="your-correct-email@example.com"
if [ "$GIT_COMMITTER_EMAIL" = "$OLD_EMAIL" ]
then
export GIT_COMMITTER_NAME="$CORRECT_NAME"
export GIT_COMMITTER_EMAIL="$CORRECT_EMAIL"
fi
if [ "$GIT_AUTHOR_EMAIL" = "$OLD_EMAIL" ]
then
export GIT_AUTHOR_NAME="$CORRECT_NAME"
export GIT_AUTHOR_EMAIL="$CORRECT_EMAIL"
fi
' <parent>..HEAD
If said commits are already merged or included in other people's work, it may be very cumbersome to change that, and you may have to live with commits attributed to the wrong author.