Created
December 29, 2019 01:52
-
-
Save keturn/9ea3aa7e005cb7cfa5b0bb236c5526e8 to your computer and use it in GitHub Desktop.
Document git fork as "Pull-Request Only"
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/bash | |
# Replace the repo's default branch with a README explaining this fork is only for its submitted pull requests. | |
set -e -x -o pipefail | |
REMOTE=origin | |
GH_USERNAME="${GH_USERNAME:-$USER}" | |
TRUNK="$(git symbolic-ref --short refs/remotes/$REMOTE/HEAD | sed "s:${REMOTE}/::")" | |
REMOTE_URL="$(git remote get-url $REMOTE)" | |
UPSTREAM_REPO="${REMOTE_URL%%.git}" | |
GIT_ROOT=$( git rev-parse --show-toplevel ) | |
PROJECT_NAME="${GIT_ROOT##*/}" | |
# Move old trunk out of the way. | |
git branch -m "$TRUNK" upstream-"$TRUNK" | |
# Make a new orphan branch with that name. | |
git checkout --orphan "$TRUNK" | |
# checkout --orphan left everything staged in the index, remove it | |
git reset | |
# Remove most files, except for those that might cause a lot of editor thrashing | |
# or things the host needs for repo metadata (e.g. LICENSE) | |
git clean --force -d --exclude=.gitignore --exclude=.editorconfig --exclude=LICENSE | |
cat > README.rst << EOF | |
Pull-Request Only Fork | |
====================== | |
This fork exists only for making pull requests against upstream. | |
See | |
* \`branches here <https://github.com/${GH_USERNAME}/${PROJECT_NAME}/branches>\`__ | |
* \`upstream repository <${UPSTREAM_REPO}>\`__ | |
* \`pull requests to upstream <${UPSTREAM_REPO}/pulls/${GH_USERNAME}>\`__ | |
EOF |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment