Skip to content

Instantly share code, notes, and snippets.

@niyari
Last active June 28, 2022 01:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save niyari/1862c2fd97f4b3e99381df55f742a027 to your computer and use it in GitHub Desktop.
Save niyari/1862c2fd97f4b3e99381df55f742a027 to your computer and use it in GitHub Desktop.
Gitのリモートmainブランチを更新する
@echo off
set GITOPTIONS=-c diff.mnemonicprefix=false -c core.quotepath=false --no-optional-locks
set GITUPSTREAM=main
set GITLOCAL=main
set GITORIGIN=main
cd %1
echo ... try stash
git stash -u | findstr "Saved working directory"
if not ERRORLEVEL 1 (
echo ... use stash
set GIT_STASH=1
) else (
echo ... skip stash
)
:GITPULL
git checkout %GITLOCAL%
git %GITOPTIONS% fetch --no-tags upstream
git %GITOPTIONS% pull upstream %GITUPSTREAM%:%GITLOCAL% | findstr "fatal:"
if ERRORLEVEL 1 goto GITPUSH
:PULLERROR
git checkout -
if defined GIT_STASH (
echo ... stash pop
git stash pop --index
)
echo pull error
exit /b 1
:GITPUSH
git %GITOPTIONS% push --tags --set-upstream origin %GITLOCAL%:%GITORIGIN%
git checkout -
if defined GIT_STASH (
echo ... stash pop
git stash pop --index
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment