This video walks you through configuration steps you'll need before you start working with version control.
Git is a fast, scalable distributed revision control system. It runs on your computer and allows you to use version control in your development work. If you're on Linux or Windows, you may need to install Git. Git is pre-installed on Macs. If you're on a Macintosh, make sure to install Xcode before you use Git. As part of Xcode's setup process, it installs a suite of command line tools, and this includes a recent version of Git. The command line tools are installed when you first launch Xcode, so make sure to run Xcode at least once before working with Git.
Version control doesn't just store list of changes made to a project over time. It stores information about the person who made those changes and is responsible for them. This information consists of a Git identity and includes both the public name that you select and an email address where you can be contacted. When you make changes whether to a public project or a multi-user project, your Git identity ensures your work is directly associated with you as a person.
For the next steps, you'll need a terminal window. If you're on Windows or Linux, open the command line. If you're on a Mac, launch the terminal application from the applications utility folder.
Here's my terminal window, it's running the bash command line. Bash is the default command line shell used by nearly every Unix operating system. Your terminal probably doesn't look exactly like mine. Many developers prefer light text on a dark background. If you have vision problems, dark text on white can be easier to read. Here are the two commands you need to enter, don't type anything yet. Let me explain what each of these commands do. The
git config command adjust settings. You use
git config to set options or to read their current values. Here you'll be setting two options, your username and your user email.
git config --global user.name "Your Name" and
git config --global user.email "[email protected]". The global flag tells git that these options apply across all the repositories that you use from your account, that is your computer account.
Once you've set this option, you won't have to do it again unless you want to start using a different identity. Notice the two dashes to the left of the word global. This is a standard way you work at the command line, two dashes means that you're setting a flag and fully spelling out the name of that flag. In this case, the
--global flag means configure this option for all the Git repositories I personally use. The remaining elements on each line say what option I'm setting and their value. They include the name of the option, including this case, username and user email and the values those are being set to. So let me show you how that looks at the command line. And if you haven't already open a terminal window now and follow along. Make sure to use your personal details, not mine and pause this video when you need to. Make sure you type extremely carefully, you need to enter these commands exactly.
First I'll configure my public username which is Erica Sadun. This is the name associated with changes that I make to projects. It is a very public and very formal identity. So make sure you spelled your name correctly and that it looks properly professional. Go ahead and configure your username on your computer. And then next, I'll configure the email associated with my user account. To do that, I enter the same
git config --global start of my command but this time I use user email and my Lambda School email address. You go ahead and do the same with your email address. Congratulations, Git is now set up to use your name and email whenever you make changes to a project because now that git knows your identity, you can start working using both local and hosted content.
There are times when using Git, when you need to edit text information. Setting up and choosing a better default editor means your interactions will be simpler and more familiar and less frustrating when, for example, you have to update a commit message. Git automatically uses whatever default text editor its associated with your shell environment. And typically this editor is vi, which can be difficult to use, especially for people new to Unix and even for people who are not new to Unix. You won't spend a lot of time using Git with a text editor but when you have to, it's good to have made sure that you configure that core editor in a way that allows you to work most effectively. You set up the editor by issuing
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 watch out for typos. If you're on a Mac, you can configure Git to use the built-in text edit editor instead. TextEdit is the Mac's natural environmental editor for text. You set it up by configuring the global core editor to use the open command.
-n flag says launch a new instance of the application even if one is already running. This makes sure you don't mess up any other work you're doing in TextEdit. And because of this, you may see two TextEdit icons open in your dock at the same time. The
-W, that's a capital W, wait flag says keep waiting until the launched application has finished running. This allows Git to wait for your editor to close the file which you do by quitting that 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 not exactly sure how your preferred text editor should be configured and it's not working the way you expect after you set it up, head over to the web and search. Chances are really good someone else who loves the same text editor that you do has already configured it for Git and has written about doing so on a message board or on Stack Overflow or in a blog post.