title: keep worktrees/branches in sync with master after every commit
body: <p>I´m banging my head against hooks and worktrees at the moment.</p>
  <p>My goal is to merge &quot;main&quot; into all worktrees whenever I do a commit on any branch.</p>
  <p>So when I commit on &quot;main&quot;, every branch merges the change.</p>
  <p>When I commit on any other branch, it instantly merges &quot;main&quot; to prevent conflicts. Other Branches try to merge but are already up to date.</p>
  <p>So i tried</p>
  <p>.git/hooks/post-commit</p>
  <pre><code>#!/bin/sh    
  for BRANCH in $(ls .git/refs/heads) 
  do      
      git checkout $BRANCH #fatal: is already checked out
      git switch $BRANCH #same error
      git merge main
      git commit $BRANCH
  done    
  exit 0
  </code></pre>
  <p>how do I switch the Branch to make the merge and commit?</p>
  <p>Thanks for your help</p>
  <p><em>edit</em>
  The problem I want to solve is:
  I do have 5-10 pretty obscure, undocumented, config files that need a common body (main) that is splat all over the place and then add/alter some lines/values for the specific device. It seems to be somewhat sensitive to the ordering of Options. Some I can move around some result in error messages (&quot;unexpected parameter in line xy&quot;).</p>
  <p>Changes are made in main as well as in the branches.</p>
  <p>I thought its easier to do the merge always and on any branch (without effect) than automate it to do it only on specific branches.</p>
  <p>So functional its equivalent to:</p>
  <ul>
  <li>Commit main: Merge to all</li>
  <li>Commit branch01: Merge main to branch01 (to create a new state to prevent conflicts).</li>
  </ul>
  <p>My worktrees are remote branches, sorry for the confusion. I´m new to git and struggling with the lingo.</p>
  <p>I did get conflicts when I created line 1 &quot;special to branch01&quot; in Branch 01, commit. Then add &quot;something I need in every config&quot; on Main line1 commit. The merge results in a conflict, because both changes are &quot;add line 1 X/Y&quot;</p>