How to Create Gitignore

Posted by
How to create gitignore file

Last updated on August 17th, 2020

A .gitignore file is a list of files to ignore when pushing files to Github.com. You can create a .gitignore file in your repository’s root directory to tell Git which files and directories to ignore when you make a commit. Here is a step by step guide on how to create .gitignore file. 

To share the ignore rules with other users who clone the repository, commit the .gitignore file into your repository. 

How to Create .gitignore File

  1. Open Terminal or Git Bash for Windows.

  2. Navigate to the location of your Git repository.

  3. If you have not yet created a .git file, run the git commit command. You can learn more on how to commit to Git.

  4. Create a .gitignore file for your repository. 
    $ touch .gitignore

  5. Use vim to open the file by running vim .gitignor. This will open a text editor called “Vim” inside your console.

  6. Press the escape key to enter and exit text-entry mode.

  7. Once you have updated your .gitignore files you can save and exit vim by pressing escape, entering :wq, and pressing return/enter

GitHub maintains an official list of recommended .gitignore files for many popular operating systems, environments, and languages in the public repository. You can also use gitignore.io to create a .gitignore file for your operating system, programming language, or IDE. For more information, see “github/gitignore” and the “gitignore.io” site.

How to Configure Ignore Files for all repositories on your computer

You can also create a global .gitignore file to define a list of rules for ignoring files in every Git repository on your computer.

  1. Open Terminal or Git Bash for Windows.

  2. Configure Git to use the exclude file ~/.gitignore_global for all Git repositories.
$ git config --global core.excludesfile ~/.gitignore_global