What Are the Differences between .gitignore and .gitkeep?

Better Stack Team
Updated on June 24, 2024

.gitignore and .gitkeep are two different files used in Git repositories for distinct purposes:


  • The .gitignore file is used to specify intentionally untracked files that Git should ignore.
  • It contains a list of file patterns or paths that Git should ignore when performing operations like git status, git add, and git commit.
  • You typically add files like build artifacts, temporary files, logs, and dependency directories to .gitignore to prevent them from being accidentally committed to the repository.
  • Git will not track or commit any files matching the patterns specified in .gitignore.
  • .gitignore does not affect tracked files already in the repository.


  • The .gitkeep file is not a standard Git feature but rather a convention used by some projects.
  • It is an empty file (or sometimes a file with a single line of content) placed in an otherwise empty directory to force Git to track the directory.
  • Git does not track empty directories by default. When you try to add an empty directory to Git, it will be ignored.
  • By adding a .gitkeep file to an empty directory, you signal to Git that the directory should be tracked, even if it's empty.
  • This convention is often used in projects to maintain directory structures in source control, even if the directories do not contain any files initially.


  • .gitignore is a standard feature of Git, whereas .gitkeep is a convention used by some projects.
  • .gitignore is used to specify files that Git should ignore, while .gitkeep is used to force Git to track otherwise empty directories.
  • Both files serve different purposes and are used in different contexts within a Git repository.
Got an article suggestion? Let us know
Licensed under CC-BY-NC-SA

This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.

Make your mark

Join the writer's program

Are you a developer and love writing and sharing your knowledge with the world? Join our guest writing program and get paid for writing amazing technical guides. We'll get them to the right readers that will appreciate them.

Write for us
Writer of the month
Marin Bezhanov
Marin is a software engineer and architect with a broad range of experience working...
Build on top of Better Stack

Write a script, app or project on top of Better Stack and share it with the world. Make a public repository and share it with us at our email.


or submit a pull request and help us build better products for everyone.

See the full list of amazing projects on github