DEV Community

Cover image for Power of .git ignore
Hasan Elsherbiny
Hasan Elsherbiny

Posted on

Power of .git ignore

in our previous articles we have discussed what is git and when to use it.
we also mentioned that git repositories are storage to place our code, but

What to store on GIT Repositories?

when it comes to GIT or any other source control we need to take care of what we are going to store in the repositories
Mainly GIT should contain our source code (and/or) building pipelines.
we also should have some concerns

  • these files are shared across the team.
    this means that this files can have many changes for everyone and every time we commit these changes we can face conflicts because we all changed that files, so what these files can be?
    simply it can be output of our applications.
    usually we write code to produce outcome such as app.exe,app.dll,app.apk, dist folder
    theses files are being changed every time we build the application
    and it's also doesn't make sense we push the code we have changed and it's outcome in the same time as other developers can simply build the application to get this out come, without need to keep face conflicts because every member has pushed his own outcome which is difference from current outcome.

  • don't store third party libraries on git
    a simple question to ask , if we can install library from the internet ,why to store it on our repo and increase the size of our repo (remember that how huge node modules for example can be)?
    so we only need to store metadata about libraries we are using in our project (which is made by default with almost all languages in files like package.json)

  • don't save credentials or local configurations
    for local configurations it's clear that every developer can have his/her own configurations like connection string ..etc
    so we can have files for development environment configuration then ignore it from git repo, in that way each developer can hold his own configurations stored locally without need to disturb other developers with conflicts and configurations changes.

but why not store credentials ?
this is only security concern as your repositories are on the cloud that mean they can get hacked or leaked so you don't breach your credentials

  • Log Files And IDE Folders most of IDES produce a folder containing it's own configuration for this project like (.vs) for visual studio , this folder shouldn't be added to GIT Repo because it will cause conflicts as each developer will have his own configurations also while development the application would produce Log file which can be huge or many files which will again will cause conflicts. add to your GIT Repository .gitignore file to ignore unwanted files or folders.

in conclusion , what to add to .gitignore?

  • Applications Outcomes (app.exe,app.dll,app.apk, dist folder ..etc)
  • Third parties libraries (packages files ,node modules ..etc)
  • Log Files
  • Environment specific configurations like (appsettings.development.json)
  • IDE Folders

one more thing to mention about .gitignore file is that , it can contains wildcards
for example

# Ignore log files
*.log

# Ignore cache directory
cache/

# ignore all .txt files but don't for file named important.txt
*.txt
!important.txt
Enter fullscreen mode Exit fullscreen mode

Top comments (2)

Collapse
 
lindiwethabo profile image
Lindiwe Thabo

I Like It

Collapse
 
hasanelsherbiny profile image
Hasan Elsherbiny

glad to hear that