I need to schedule a task in Windows Server 2008 R2 to automatically push files from a folder to Github Enterprise (I don't think the "Enterprise" part will make it different than regular Github, except that ssh authentication is required).
Here's what I've done:
add
, commit
, and push
steps to make sure it works that wayUnfortunately, the task fails because I am not writing the .bat file correctly.
This was my attempt at the .bat file:
echo git add . | "C:\Program Files\Git\bin\git.exe"
echo git commit -m 'scheduled commit' | "C:\Program Files\Git\bin\git.exe"
echo git push | "C:\Program Files\Git\bin\git.exe"
I found a good resource on how to do this, but it is unfortunately very Linux-specific.
Just do:
git add .
git commit -m 'scheduled commit'
git push
Or, if git is not in your path:
"C:\Program Files\Git\bin\git.exe" add .
"C:\Program Files\Git\bin\git.exe" commit -m 'scheduled commit'
"C:\Program Files\Git\bin\git.exe" push
And depending on what you want to achieve,
git commit -a -m 'scheduled commit'
to commit only tracked file that changed, or :
git add -A
git commit -m 'scheduled commit'
to commit new file or delete is even better...
The above answer from Philippe works. However, it does not work if it is run somewhere the errorlevel is checked after the execution of commit (like in Jenkins). A small modification solves that:
git add -A
git diff-index --quiet HEAD || git commit -m "scheduled commit"
This is explained further in the original answer on https://devops.stackexchange.com/a/5443
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With