Last active
March 28, 2019 13:48
-
-
Save daniel-bytes/2775a6d20414ad0a5e0b2443e833d03d to your computer and use it in GitHub Desktop.
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
function git-reset-commits(){ | |
branch=$(git branch | grep \* | cut -d ' ' -f2) | |
remote=upstream | |
basebranch=$branch | |
if [ "$#" = 1 ]; then | |
basebranch=$1 | |
elif [ "$#" -gt 1 ]; then | |
remote=$1 | |
basebranch=$2 | |
fi | |
git fetch $remote $basebranch | |
commit=$(git merge-base $basebranch $branch) | |
echo "resetting current branch $branch to base branch $remote/$basebranch via commit $commit" | |
git reset $commit | |
} | |
function git-checkout-pr(){ | |
pr=$1 | |
remote=upstream | |
branch="pr-$pr" | |
if [ "$#" = 2 ]; then | |
branch=$2 | |
elif [ "$#" -gt 2 ]; then | |
remote=$2 | |
branch=$3 | |
fi | |
echo "checking out pull request $pr from remote $remote to branch $branch" | |
git fetch $remote pull/$pr/head:$branch | |
git checkout $branch | |
} | |
function git-rebase(){ | |
remote=upstream | |
branch=$(git branch | grep \* | cut -d ' ' -f2) | |
if [ "$#" = 1 ]; then | |
branch=$1 | |
elif [ "$#" -gt 1 ]; then | |
remote=$1 | |
branch=$2 | |
fi | |
echo "rebasing branch $branch from remote $remote" | |
git fetch $remote $branch | |
git rebase $remote/$branch | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment