Skip to content

Instantly share code, notes, and snippets.

@electrum
Last active June 2, 2020 12:04
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save electrum/e26bdd9c1b06ffcd790d to your computer and use it in GitHub Desktop.
Save electrum/e26bdd9c1b06ffcd790d to your computer and use it in GitHub Desktop.
Git Scripts

Install the following programs and configure them with permissions to access your GitHub profile:

These scripts assume the following two remotes exist:

  • origin: your fork
  • upstream: the upstream repository

Using git-land.sh:

  • Create a branch for your change: git checkout -b foo
  • Push branch: git push -u origin foo
  • Create pull request: hub pull-request
  • Land pull request: git-land.sh foo

Merging a pull request:

  • Create rebased branch for pull request: git-pr-checkout.sh 1234
  • Push pull request: git-pr-push.sh 1234
#!/bin/sh -eux
BRANCH=$1
git checkout $BRANCH
git pull --rebase upstream master
git push --force origin HEAD:$BRANCH
git push upstream HEAD:master
git checkout master
git pull --ff-only upstream master
git push origin HEAD:master
git branch -d $BRANCH
git push --delete origin $BRANCH
#!/bin/sh -eux
PR=$1
BRANCH=pr$PR
git fetch upstream pull/$PR/head
git checkout -b $BRANCH FETCH_HEAD
git pull --rebase upstream master
#!/bin/sh -eux
PR=$1
BRANCH=pr$PR
git checkout $BRANCH
git pull --rebase upstream master
git push upstream HEAD:master
git checkout master
git pull --ff-only upstream master
git push origin HEAD:master
git branch -d $BRANCH
ghi comment --close -m 'Merged, thanks!' $PR
#!/bin/sh -eux
git push origin master --tags
git push upstream master --tags
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment