348

I have a project hosted in Git stash (now rebranded as Bitbucket Server). It is built using Jenkins. Now I made a typo while installing my Git locally. Like @ab.example instead of @abc.example

After every build, Jenkins sends email notifications and it picks up my incorrect email address from Git commit and tries to send it.

Even after I have changed the email address in my local Git, I still see Jenkins sending the emails to the old incorrect address.

How can I fix this?

Stephen Ostermiller
  • 23,933
  • 14
  • 88
  • 109
mani_nz
  • 4,522
  • 3
  • 28
  • 37
  • Try `Editable Email Notification` in `Post-build Actions`. You can define the recipient list by literal strings or variables of email addresses. As to the incorrect email in the early commits, you could use `git filter-branch --env-filter` to modify. But this rewrites the commit history. It's not recommended. – ElpieKay Jun 14 '16 at 07:38
  • I know about the post build step. That is how I'm overriding the issue now. – mani_nz Jun 14 '16 at 08:46

6 Answers6

581

Locally set email-address (separately for each repository)

  1. Open Git Bash.

  2. Change the current working directory to the local repository in which you want to set your Git config email.

  3. Set your email address with the following command:

git config user.email "your_email@abc.example"
  1. Confirm that you have set your email address correctly with the following command.
git config user.email

Globally set email-address (only used when nothing is set locally)

  1. Open Git Bash.

  2. Set your email address with the following command:

git config --global user.email "your_email@abc.example"
  1. Confirm that you have set your email address:
git config --global user.email

Or using environment variables

  1. GIT_COMMITTER_EMAIL=your_email@abc.example
  2. GIT_AUTHOR_EMAIL=your_email@abc.example

PD: Info from GitHub official guide

Benjamin Loison
  • 3,782
  • 4
  • 16
  • 33
Marc
  • 6,154
  • 1
  • 15
  • 10
  • I have done this already and the email address is changed in git. But Jenkins still refers to the old email address from Git.. Strange!! – mani_nz Jun 14 '16 at 08:46
  • 7
    The commits that you have made already will have an old email address. Only new commits will have the new e-mail address. If you want to change the e-mail address in existing commits, see [how to change an author of a commit](http://stackoverflow.com/questions/750172/change-the-author-of-a-commit-in-git). – fracz Jun 14 '16 at 09:02
  • Can I add a global email which dominates all repos although a repo(local) mail exists? – Timo Feb 12 '21 at 20:17
  • You can use `git config --get user.email` to check the value – AmanicA Nov 24 '21 at 00:31
  • After changing your email, if you want your previous commit (before the email change) to be counted now as your contribution. You need to rewrite your history and if you want to do while preserving author/commiter name ( if it's not yours) and timestamp: https://gist.github.com/bgromov/a1905055a8b9cdbeb1d2a87e70920cc8?permalink_comment_id=4222917#gistcomment-4222917 – behanzin777 Jul 06 '22 at 11:26
115

According to the git documentation, all you should have to do is re-run

$ git config --global user.name "John Doe"  
$ git config --global user.email johndoe@example.com  

Then just check to make sure the change took effect

$ git config --list

This is listed in the Pro Git book, written by Scott Chacon and Ben Straub

1.6 Getting Started - First-Time Git Setup

Donald L Wilson
  • 1,291
  • 1
  • 8
  • 10
10

This will overwrite the user's name and email in the last commit.

"git -c user.name="your name" -c user.email=youremail@email.com
commit --amend --reset-author"
Isa
  • 31
  • 6
user3143487
  • 235
  • 3
  • 7
10

To set your global username/email configuration:

  1. Open the command line.

  2. Set your username:

    git config --global user.name "FIRST_NAME LAST_NAME"

  3. Set your email address:

    git config --global user.email "MY_NAME@example.com"

To set repository-specific username/email configuration:

  1. From the command line, change into the repository directory.

  2. Set your username:

    git config user.name "FIRST_NAME LAST_NAME"

  3. Set your email address:

    git config user.email "MY_NAME@example.com"

  4. Verify your configuration by displaying your configuration file:

    cat .gitconfig

For more information and for other version control systems .. => SeeThis

awgtek
  • 1,483
  • 16
  • 28
Endriyas
  • 546
  • 6
  • 13
1

The commands explained set the email in the .git/config locally:

[core]
    repositoryformatversion = 0
    filemode = true
    bare = false
    logallrefupdates = true
[remote "origin"]
        url = https://username:password@git.mydomain.io/username/repo.git
        fetch = +refs/heads/*:refs/remotes/origin/*
[branch "master"]
        remote = origin
        merge = refs/heads/master
[branch "beta"]
        remote = origin
        merge = refs/heads/beta
[user]
        email = pippo.caio@sempronio.io
gdm
  • 7,647
  • 3
  • 41
  • 71
0

Edit your email directly in the JENKINS_HOME/users/YOUR_NAME/config.xml configuration file and restart the Jenkins server

Victor Procure
  • 886
  • 1
  • 6
  • 17