DEV Community

Rocktim Saikia
Rocktim Saikia

Posted on


✨ module to read git user config from the system and return it as a JSON object.

GitHub logo rocktimsaikia / read-git-user

Reads the username and email from `.gitconfig` and returns it as json object

Read-git-user is a tiny 1.3kB✨ module that can be used to retrieve the git username and email right from the systems global .gitconfig file.

How this works is that the module looks for HOME || USERPROFILE and reads the ini file from there and returns it as a parsed JSON object.


import readGitUser = require('read-git-user');

(async () => {
        const gitUser = await readGitUser();
        //=> {user: rocktimsaikia, email:}

        const gitUser = readGitUser.sync()
        //=> {user: rocktimsaikia, email:}
Enter fullscreen mode Exit fullscreen mode

[ PS: I created this tool to use it in a project that I am working on. I thought someone might find it handy so made a quick post. Leave a star at the repo 🌟 if find this helpful. Thanks for reading 👋]

Top comments (0)


11 Tips That Make You a Better Typescript Programmer

1 Think in {Set}

Type is an everyday concept to programmers, but it’s surprisingly difficult to define it succinctly. I find it helpful to use Set as a conceptual model instead.

#2 Understand declared type and narrowed type

One extremely powerful typescript feature is automatic type narrowing based on control flow. This means a variable has two types associated with it at any specific point of code location: a declaration type and a narrowed type.

#3 Use discriminated union instead of optional fields


Read the whole post now!