Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Ruby Build a Todo List Application with Rails 4 Build a Todo List Application with Rails 4 Set up Git and Add Gems

What is the reason for using these git commands prior to git init? git config --global user.email and user.name

Are these commands generally run on new machines and environments (vagrant server in this instance) and for what reason?


2 Answers

Stone Preston
Stone Preston
42,016 Points

a name and an email address are associated with each commit. It is really just a label and is convenient to see the name and the email of someone who made the commit.

It is not required though, you can simply put a blank for those if you wanted:

git config --global user.name ""
git config --global user.email ""

you may not want your name or email exposed.

according to the git documentation

Git comes with a tool called git config that lets you get and set configuration variables that control all aspects of how Git looks and operates. These variables can be stored in three different places:

/etc/gitconfig file: Contains values for every user on the system and all their repositories. If you pass the option --system to git config, it reads and writes from this file specifically.

~/.gitconfig or ~/.config/git/config file: Specific to your user. You can make Git read and write to this file specifically by passing the --global option.

so by passing in the global flag, you set those variables for your user account, this way no matter which repo on your system you are in, the variables will have the same value everywhere.

Stone Preston Thanks!

Clinton Baker
Clinton Baker
9,344 Points

I don't think you actually have to do them before the git init command, but you'll need to do them before you commit anything, that way it can log who actually did the commit. user.name sets the name and user.email gives it an email in case anyone else working on the project needs to contact you about your work. At least that's how I understand it.