Lesson Weekend

After installing Git, we recommend a few Git configurations that will make using Git on your own device similar to the experience you will have at Epicodus. These configurations are already set up on the Epicodus machines and will not need to be implemented when in class.

Make VS Code the Default Editor

Mac users: To make Git use the VS Code text editor to interact with you instead of vim (or whatever your system's default terminal editor may be) run the following two commands:

$ git config --global core.editor "code --wait"

Windows users: You should've already set up VS Code to be the default editor when you installed Git Bash.

Configure Color Output

Setting this global configuration will color code Git information in the terminal for easier reading:

$ git config --global color.ui true

Configure Global Author Settings

We can set up a global configuration for our git user name and email. You should only do this on your personal machine.

$ git config --global user.name "Padma Patil"
$ git config --global user.email "[email protected]"

This sets the name and email for every save that is made in any directory anywhere on the device. If you are setting this on your personal device, you will only have to set this once for it to be set on every project.

Configure Local Author Settings

Note that you can override the global setting for a single repository by removing the global flag:

$ git user.name "Jasmine Hart"
$ git user.email "[email protected]"

If Padma's credentials were set up globally and Jasmine's were set up in an individual hello-world project, when commits are added to the hello-world project, Jasmine's configuration would be used. Padma's would still be used for all projects not in the hello-world directory.

Ignore files

Once a Git repository is created in your project directory, Git will track every file and folder there, even the ones you may not want included in your project! For example, operating systems often add files without input from you. For example, Macs create hidden files in most directories called .DS_Store. Windows directories often contain files called Thumbs.db.

To ignore these files in all of your Git repositories, you can create an "ignore file" in your home directory with the global tag to indicate this is for every Git repository that is created anywhere on the device.

Here are the steps:

1. Navigate to your home directory:

$ cd ~

2. Create an empty, new file in your home directory called .gitignore_global:

$ touch .gitignore_global

3. Open your new file in VS Code (or you can use an editor in the terminal like Nano or Vim, if you prefer):

$ code .gitignore_global

4. Within the file you've just opened in VS Code, or a Terminal text editor (like Nano or Vim), add rules for the files and file types you want ignored by creating a list. Each kind of file should reside on a new line. (See example below)

At this point, you may not know what files you'd want to ignore globally. That's fine. To get started, copy and paste the list below into your .gitignore_global file (from GitHub's list). This will ensure that pesky files generated by your operating system will not fill up your project folders:

# OS generated files #
######################
.DS_Store
.DS_Store?
._*
.Spotlight-V100
.Trashes
ehthumbs.db
Thumbs.db

As you gain experience with the kinds of files you don't want cluttering your Git repository, you can return to your .gitignore file and add others.

5. Tell Git to use this file as a rule for all of the coding projects you set up on this computer:

$ git config --global core.excludesfile ~/.gitignore_global

One last thing: note that all file names that begin with a . are hidden, so files like .gitignore and .gitignore_global won't be visible either in the GUI (graphical user interface) or with the ls command. Instead, you'll need to use the all flag like this ls -a in order to see these hidden files.

Terminology


  • Vim: Default text editor designed for use from the command line.

  • Global: An option in many command line commands that applies the changes everywhere instead of just in the current directory.

Configurations


Make Visual Studio Code Your Default Git Editor

$ git config --global core.editor "code --wait"

Color Output

$ git config --global color.ui true

Git Ignore Files

  • Add this file to your home directory:
.gitignore_global
# OS generated files #
######################
.DS_Store
.DS_Store?
._*
.Spotlight-V100
.Trashes
ehthumbs.db
Thumbs.db
  • Run this command to use it:
$ git config --global core.excludesfile ~/.gitignore_global

Lesson 7 of 8
Last updated October 12, 2020