How To Configure Git: A Beginners Guide

September 24, 2018
Image of a code snippet on a screen

This article walks you through configuration steps you'll need before you start working with version control. 

Learning to configure Git is essential to any new developer. It will not only help keep work organized, but will catalogue the development process both for beginners and seasoned developers. In this post we will discuss how to establish a Git identity and configure a default editor, which are the basic building blocks and most essential configuration tasks for Git. 

How to establish a Git identity 

Git is a fast, scalable distributed revision control system allowing use of version control in development work. Version control not only stores a list of changes made to a project over time, it has the capability to store information about the person responsible for making changes via the users Git identity. This identity includes both a public name and an email address selected by the user. When changes are made to a public or multi-use project, this Git identity additionally ensures work stays directly associated with each unique user. 

Follow these 3 tips to establish a Git identity:

1.    Consider your computer. To get started using Git, factor in which computer system you plan to work with. If working on Linux or Windows, you may need to install Git. If working on a Mac, Git will be pre-installed but you will still need to install and run Xcode at least once prior to using Git. This is due to Xcode's setup process, which will install a suite of command line tools, including the most recent version of Git. 

2.    Open or Launch a Terminal Window. Windows or Linux users will open the command line to create a terminal window. Mac users will launch the terminal application from the applications utility folder. Inside the terminal window, users will be able to run the bash command line. Bash is the default command line shell used by nearly every Unix operating system, and developers utilize git config to set options and read their current values. Consider the two commands below that users will need to enter first. These git config commands adjust settings, specifically your username and email:

git config --global user.name “Your Name”

git config --global user.email you@example.com

By using these commands, this global flag will tell git that these options apply across all repositories you use from your account, and once you've set this option, you won't have to do it again unless you want to configure a new identity. To do this, simply run the command with the --global option with a project. Now consider the two dashes to the left of the word global. This is standard within the command line. Two dashes indicate setting a flag and fully spelling out the name of that flag. In this case, the --global flag means to configure this option for all the Git repositories the user will personally use. The remaining elements on each line indicate the options and values the user is setting – in this case the name of the option, username and user email, and their values. 

Pro Tip: Every terminal will look different depending on a developer’s preferences. Although light text on a dark background may successfully cut glare and reduce blue light, if you have vision problems, dark text on white can be easier to read and can more successfully prevent or prolong the onset of eye strain. 

3.    Configure a public username. Establishing yourself as a Git setup user with a Git set email is the most important step. This should be a Git set name you want associated with changes you make to projects. This will be your public and formal identity, so be sure it looks and sounds professional with proper spelling and grammar. After you have chosen your username, you may configure it on your computer and then through the Git set email associated with your user account. To do this, simply plug the username you have chosen into the git config command listed above in step 2, along with your email address. 

Now you have established your Git set email and username, whenever you make changes to a project, Git will know your identity. This means you can start working using both local and hosted content and can also configure the default text editor that will be used when Git requires you to edit text information. If not configured, Git will use your system’s default editor. 

Setting up a Git default editor

By setting up and choosing a better Git default editor, your interactions will be simpler, more familiar, and less frustrating when, for example, you have to update a commit message. Git automatically uses the default text editor associated with your shell environment. Typically, this editor is vi, which can be difficult to use, especially for users new to Unix (and sometimes for users familiar with Unix, too). Users will spend minimal time using Git with a text editor, but when it’s necessary, it’s vital to make sure you have configured the core editor in a way that allows you to work most effectively. 

To set up your default text editor, first start with the basics. Issue a git config --global like before, followed by core.editor and the name of the editor you'd like to use. For example, you might use pico or nano as your primary editor on a Linux system. The editor name is string base, so be mindful of typos. Your commands might look like this:

         bash-3.2$ git conf --global core.editor “pico”

         bash-3.2$ git conf --global core.editor “nano”

         bash-3.2$ git conf --global core.editor “emacs”

         bash-3.2$ git conf --global core.editor “vim”

Setting up Git on a Mac, users may use the built-in TextEdit editor instead, the natural environmental editor for Mac text. To establish it, users simply configure the global core editor to use the open command. The -n flag will signal to launch a new instance of the application even if one is already running. This guarantees you won't interfere with other work in TextEdit. Additionally, you may see two TextEdit icons open in your dock at the same time. Your commands might look like this:

         bash-3.2$ git conf --global user.name “User Name”

         bash-3.2$ git conf --global user.email “user@BloomTech.com”

         bash-3.2$ git conf --global core.editor “open – W – n”

The -W, a wait flag, indicates the user must wait until the launched application has finished running. This allows Git to wait for your editor to close the file, allowing you to quit the associated version of TextEdit. Depending on your operating system and the text editor you choose, you may need to issue similar wait flags in your core editor setup. If you're unclear how your preferred text editor should be configured and your expectations are not met after setup, you may need to search the internet or Bloom Institute of Technology (formerly known as Lambda School) help channels for support. Chances are, someone with the same admiration for your text editor may have already configured it for Git and written about the solution on a Slack board or blog post. 

Now that you have learned the essential configuration tasks for Git, you will have a solid foundation to begin your journey as a new developer.

For more information on configuring Git and configuring a default editor, watch our Configuring Git and Configuring a Default Editor video tutorial.