-1

I learned how to download a Git repository without a history (to save disk space and Internet traffic). I created file git-no-history.bat with this content:

git clone --depth 1 %1

Now I need to create files git-check.bat (check if my version is the last one) and git-update.bat (get to the last version). What should I write here?

If possible, also describe how to do these three operations in TortoiseGit.

No Linux Bash please; I have zero experience with it.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
puppon -su
  • 137
  • 2
  • 8
  • 1
    Possible duplicate of [Check if pull needed in Git](https://stackoverflow.com/questions/3258243/check-if-pull-needed-in-git) – pjpj Oct 01 '17 at 10:36
  • @WendingPeng i don't understand linux bash, sorry – puppon -su Oct 01 '17 at 10:46
  • @puppon-su, the accepted answer on that question contains very little bash. Please read it and try to understand what it is saying, then apply your learning to your own situation. – ChrisGPT was on strike Oct 01 '17 at 14:55

1 Answers1

0

git-check.bat:

@echo off

git fetch origin
if %errorlevel% neq 0 goto end



rem #get number of new commits
FOR /F "delims=" %%i IN ('git rev-list HEAD...origin/master --count') DO set numofupdates=%%i

if [%numofupdates%]==[0] goto nothing_new


rem #get list of new commits
git log HEAD..origin/master --oneline


set ask=
set /p ask=Update? (y/n)
if not [%ask%]==[y] goto nah

echo Updating...
git merge origin
echo Done!
goto end

:nah
echo Nah...
goto end

:nothing_new
echo Nothing new
goto end

:end

rem Looks like `git pull` is the same as `git fetch origin` plus `git merge origin`.

I'll live without git-update.bat, it will require doing git fetch origin twice. Maybe there is a way to get time of last fetch, but that's too complex for bat.

puppon -su
  • 137
  • 2
  • 8