Git… Please allow me to introduce myself.

Colin Standefer
Frontend Weekly
Published in
3 min readNov 22, 2016

Kudos to you if you caught the small nod to the Rolling Stones’ lyrics to “Sympathy for the Devil” there in the title because that’s exactly what was going through my head. The Rolling Stones were one of my dad’s favorite bands, and he always had a thing for that song. If you’ve never heard that song, by all means, go listen to it before you read this article. It’s such a fantastic song! Anyhow…

Alright, everybody. This is a great lesson that all of your employers and collaborators will thank you for reading and implementing. This is the lesson where you get to program Git to know who you are if it doesn’t already know. Furthermore, you get to figure out who Git thinks you are!

Let’s take a look at the 4 commands to assign name/email and figure out name/email.

git config user.namegit config user.emailgit config --global user.name <your name in double quotes>git config --global user.email <your email in double quotes (or not in double quotes... it works either way)>

So if we use git config user.name or git config user.email, what we get for the output is the user’s name or e-mail address. You can easily figure out who Git thinks you are by typing this command into your command line while in the Git repo in question. These are your identifying commands.

However, let’s say you need to change the user. Well, for that you’d use git config --global user.name <your name in double quotes>.

If you need to change the e-mail. Well, for that you’d use git config --global user.email <your e-mail in double quotes (or not in double quotes... it works either way)>.

Let’s see these commands in action! Here’s a demo screenshot:

Well, what do ya know?… It worked!

If you were to commit with different usernames and e-mails that you’ve changed, you would also see the appropriate usernames and e-mails that you configured to Git to know represented in your commit logs when you type git log — a topic for another upcoming Git article.

Instead of looking at a screenshot, create a demo repo and mess around with this stuff, make some commits, change the username and email, make some more commits, run a git log, and EXPERIMENT. The programming community pays a lot of homage to creating and experimenting as the basis of learning programming; yet, I don’t see a lot of developers, particularly juniors, really taking this to heart. Yes, it’s time-consuming, but you really burn the information into your mind.

Now that I’ve said that…

There is one caveat to using --global, which I need to mention here. It will change the user or email — whichever you chose — across all of the Git repositories on your local machine… not just the one you’re in.

The solution to this, however, is just as simple as using --global. DON’T USE --global. Really… it’s that simple. By not using --global, you are telling Git to change the user or e-mail in that specific repository rather than across all your repositories. It’s up to you as far as how you do this. Think about your case and then implement your necessary solution. Maybe I’m being naive, but that’s pretty much all programming, and a lot of life for that matter, in a nutshell. Seriously, though… consider and implement. That’s it.

Thanks for reading! I hope this helped because that’s why I’m writing these Git mini-tutorials. I’ll be covering a whole slew of Git commands, their usages, and more in my upcoming articles. Until then, I bid you adieu.

--

--