Skip to content

Instantly share code, notes, and snippets.

@jurchiks
Last active January 22, 2021 02:13
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 jurchiks/6dc0858454f0798563247ceb1bb4a3de to your computer and use it in GitHub Desktop.
Save jurchiks/6dc0858454f0798563247ceb1bb4a3de to your computer and use it in GitHub Desktop.
Switch to master, pull from upstream, push to origin (+optionally delete feature branch)
@echo off
set main_branch=master
REM store current branch name in variable
for /f "delims=" %%a in ('git rev-parse --abbrev-ref HEAD') do @set branch=%%a
git checkout %main_branch% & git pull upstream %main_branch% & git push
REM this GOTO crap is only necessary because CMD doesn't support IF (foo && bar)
IF "%1"=="delete" (
goto delete
)
IF "%1"=="back" (
goto back
)
goto end
:delete
REM if need be, delete that branch
IF NOT %branch%==%main_branch% (
echo "deleting branch %branch%"
git fetch --prune
git branch -d %branch%
git push origin --delete %branch%
)
goto end
:back
REM if need be, switch back to the current branch
IF NOT %branch%==%main_branch% (
echo "switching back to %branch%"
git checkout %branch%
)
goto end
:end
#!/bin/bash
main_branch=master
# store current branch name in variable
branch=`git rev-parse --abbrev-ref HEAD`
git checkout $main_branch && git pull upstream $main_branch && git push
# if need be, delete that branch
if [ $branch != $main_branch ] && [ "$1" == "delete" ]; then
echo "deleting branch $branch"
git fetch --prune
git branch -d $branch
git push origin --delete $branch
fi
# if need be, switch back to the current branch
if [ $branch != $main_branch ] && [ "$1" == "back" ]; then
echo "switching back to $branch"
git checkout $branch
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment