@echo off SET SOME_VAR="first.txt" DEL /S "%SOME_VAR%" || echo "file not found" SET SOME_VAR="second.txt" DEL /S "%SOME_VAR%" || echo "file not found" CALL :_ex EXIT /B %ERRORLEVEL% :_ex echo >"first.txt" git add . git commit -m "First commit" echo "one">>first.txt git commit -am "Added one" echo "two">>first.txt git commit -am "Added two" git push -u origin master git reset --hard HEAD~1 echo "A B C D F G">second.txt EXIT /B 0