Autoplay

    Practical Git: Remove all unnecessary git tracking with a global .gitignore file

    Trevor MillerTrevor Miller

    If you regularly use code editors, GUI tools or other programs that automatically create files and folders, you may want to set up a global .gitignore file which will apply to every repo on your machine. In this lesson, we show how to do that by creating a .gitignore_global file with the dotfiles in our ~/ root directory, and then link it to all git repos using our global .gitconfig.

    gitgit
    Code

    Code

    Become a Member to view code

    You must be a Member to view code

    Access all courses and lessons, track your progress, gain confidence and expertise.

    Become a Member
    and unlock code for this lesson
    Transcript

    Transcript

    00:00 If we know that every gitrepo on a machine is going to need to ignore a specific file or folder type, we can create a global .gitignore. To do this, let's first change directories to where we store our doc files, which in this case will be my user root.

    00:14 Next, let's create a .gitignore global file. The name of this file is up to you. This is the convention that GitHub suggests. Let's open this file in our code editor and we can add any file or folder patterns that we would like to ignore in all of our gitrepos. Let's save and close this file and return to our command line.

    00:33 We can run gitconfig -- global core.excludesfile. The path of where we've placed our global gitignore file. When we create new gitrepos, and files or folders that match our patterns in our gitignore are created, Git can ignore them from anywhere on our system.

    Discuss

    Discuss