diff --git a/build/simulink_codegen/writegitinfoheader.m b/build/simulink_codegen/writegitinfoheader.m
index 9dc392c906997835824a6009a9a696c79fd69b3b..828668285288099c48af884cbace47494b7a1d24 100644
--- a/build/simulink_codegen/writegitinfoheader.m
+++ b/build/simulink_codegen/writegitinfoheader.m
@@ -2,6 +2,22 @@ function writegitinfoheader()
    % max description length
    maxdesclen=1024;
 
+   % Git checks first
+   
+   % 1) check repo cleanlyness
+   % TODO: check that the output of 'git status -procelain' is empty
+   [~,result] = system('git status --porcelain');
+   if ~isempty(result)
+       error('the working copy is not clean, please commit changes first.');
+   end
+   
+   % 2) check local and remote hash are matching (in synch working copy)
+   [~,localhash]  = system('git rev-parse @');
+   [~,remotehash] = system('git rev-parse @{u}');
+   if ~strcmp(localhash, remotehash)
+       error('the working copy is not in sync with its origin, please push first.');
+   end
+   
    % first we get TCV current shot number, to be used for tagging
    mdsconnect('tcvdata');
    curshot=mdsvalue('current_shot("tcv_shot")');