Skip to content

Instantly share code, notes, and snippets.

@jcfranco
Created November 7, 2023 19:28
Show Gist options
  • Save jcfranco/2b90053ada184170e6b2298ae28daa21 to your computer and use it in GitHub Desktop.
Save jcfranco/2b90053ada184170e6b2298ae28daa21 to your computer and use it in GitHub Desktop.
Script to automate PR adoption steps from https://github.com/diaspora/diaspora/issues/4340
#!/bin/zsh
# Check for correct number of arguments
if [ "$#" -ne 2 ]; then
echo "Usage: $0 <repo-url> <branch-name>"
exit 1
fi
# Assign arguments to variables
REPO_URL=$1
BRANCH_NAME=$2
# Extract the name of the remote from the URL
REMOTE_NAME=$(echo $REPO_URL | sed 's#.*/\([^/]*\)\.git#\1#g')
# Add the remote repository
git remote add $REMOTE_NAME $REPO_URL
# Fetch from the remote repository
git fetch $REMOTE_NAME
# Checkout and create a new branch tracking the remote branch
git checkout -b $BRANCH_NAME $REMOTE_NAME/$BRANCH_NAME
# Push the new branch to the origin and set upstream
git push -u origin $BRANCH_NAME
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment