Created
July 8, 2021 08:43
-
-
Save pilhuhn/4d01b7c5e76d2b1e58b80aee8eec9b81 to your computer and use it in GitHub Desktop.
My git helper scripts to do the update from upstream dance
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# Usage: git-fups [-F] | |
# -F means force update | |
# normally the script stops when the local branch has changes. | |
# sometiemes one just wants to pull in changes from remote, so -F can be used | |
CBRANCH=`git rev-parse --abbrev-ref HEAD` | |
MAIN_BRANCH="main" | |
git branch | grep ". main" | |
if [ $? -ne 0 ] | |
then | |
MAIN_BRANCH="master" | |
fi | |
if [ "X$1" == "X-F" ] | |
then | |
export force=true | |
else | |
export force=false | |
fi | |
if [ "X`git status --porcelain`" != "X" ] | |
then | |
echo "Repo not clean" | |
if [ $force == true ] | |
then | |
echo "Forcing update" | |
CREF=`git stash create` | |
git reset --hard | |
else | |
exit 1 | |
fi | |
fi | |
git checkout $MAIN_BRANCH | |
git fetch upstream --tags | |
if [ $? -ne 0 ] | |
then | |
echo "There is a problem with upstream. Aborting" | |
exit 1 | |
fi | |
git rebase upstream/$MAIN_BRANCH | |
if [ $? -ne 0 ] | |
then | |
echo "Problem with rebase. Aborting" | |
exit 1 | |
fi | |
git push | |
git fetch --prune | |
git checkout $CBRANCH | |
git rebase $MAIN_BRANCH | |
if [ "X$CREF" != "X" ] | |
then | |
git stash apply $CREF | |
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# Usage git-pr [remote] <pr-number> | |
# The script pulls in the pr-branch with the given pr-number | |
# from upstream. If a different remote is used, it can be | |
# passed in as 1st parameter. | |
set -x | |
if [ $# -eq 2 ] | |
then | |
WHERE=$1 | |
shift | |
else | |
WHERE='upstream' | |
fi | |
git fetch $WHERE pull/$1/head:pr-$1 | |
git checkout pr-$1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment