Home > Blockchain >  Why local git repo is asking for email?
Why local git repo is asking for email?

Time:06-11

I understand why Git would want to know your data if you try to push / pull to remote branch. But if I want to have local repo that would exist only on my laptop, why would it want me to provide my credentials before committing to it?

*** Please tell me who you are.

Run

  git config --global user.email "[email protected]"
  git config --global user.name "Your Name"

CodePudding user response:

Because this is your identity, or it specifies the identity of a person who works in a repo. Imagine that two person work on a same system for some reasons. So everybody can works in his or her own repo with different identity.

CodePudding user response:

Git commits have metadata associated with them like the time. The author of the commit (their name) and the authors email are part of that metadata. You could stub these as empty strings or bogus values if it's purely a project you're doing locally but it's pretty important information in a collaborative environment for things like blame (who wrote what and when).

From: https://git-scm.com/book/en/v2/Git-Internals-Git-Objects

[...] author/committer information (which uses your user.name and user.email configuration settings [...]

CodePudding user response:

Because the author and committer identity is a mandatory component of every GIT commit file. As you can see in the following sources:

  • Git Objects

    The format for a commit object is simple: it specifies the top-level tree for the snapshot of the project at that point; the parent commits if any (the commit object described above does not have any parents); the author/committer information (which uses your user.name and user.email configuration settings and a timestamp); a blank line, and then the commit message.

  • Git File format

    A commit file looks like this:

    commit <content length><NUL>tree <tree sha>
    parent <parent sha>
    [parent <parent sha> if several parents from merges]
    author <author name> <author e-mail> <timestamp> <timezone>
    committer <author name> <author e-mail> <timestamp> <timezone>
    
    <commit message>
    

If you don't tell Git who you are, it cannot create well-formed commit files. So ... it insists that you tell it.

There is nothing stopping you from using fake identity information in your local repository, but it is liable to come back and bite you if you later need to publish the commits that you made.

CodePudding user response:

It's common mistake to think that this email is your credential but it's in fact just an information used when git create commits.

The proof is that you could put whatever wrong or no-reply email even if it could be a bad idea.

The real secure way to ensure that someone created a specific commit is to sign it.

And your credentials are used only for connecting to the remote server to fetch/push your commits.

  •  Tags:  
  • git
  • Related