In Syncthing, ignore patterns are used to exclude certain files or directories from synchronization. These patterns are defined in a file called .stignore inside the folder being synced. Understanding how ignore patterns work helps control what gets synchronized between devices.


How Ignore Patterns Work

  1. Location: Ignore patterns are written in a .stignore file located inside the Syncthing folder.
  2. Syntax: Each line in .stignore represents a pattern defining files or directories to ignore.
  3. Matching: Syncthing uses a pattern-matching system similar to .gitignore.

Pattern Syntax

Here are the main rules for writing ignore patterns:

1. Basic Ignoring

  • Ignore specific files or folders:
    myfile.txt       # Ignores 'myfile.txt'
    temp/            # Ignores 'temp' directory and its contents
    

2. Wildcards

  • * (Matches anything except a directory separator /)

    *.log            # Ignores all files ending in .log
    
  • ** (Matches across directories)

    logs/**          # Ignores everything inside the 'logs' folder
    **/backup/       # Ignores any 'backup' folder at any depth
    

3. Negating Ignore Rules

  • Use ! to re-include files that were ignored by previous rules.
    *.log            # Ignore all .log files
    !important.log   # But include 'important.log'
    

4. Comments

  • Use # to add comments (ignored by Syncthing).
    # This is a comment
    

Example .stignore File

# Ignore all .tmp files
*.tmp

# Ignore the node_modules folder
node_modules/

# Ignore all logs but keep 'server.log'
logs/**
!logs/server.log

How Syncthing Processes Ignore Patterns

  1. Patterns are evaluated top to bottom.
  2. If a file matches multiple patterns, the last matching rule applies.
  3. Ignored files are not deleted, but they won’t sync.
  4. Patterns do not apply retroactively—if a file was already synced, it remains on other devices.

Would you like an example for a specific use case? 😊