Skip to content

Instantly share code, notes, and snippets.

@jcfranco
Last active September 14, 2024 05:13
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 owner from the URL (assuming URL format is like: https://github.com/owner/repo.git)
REMOTE_OWNER=$(echo $REPO_URL | sed 's#.*/\([^/]*\)/[^/]*\.git#\1#')
# Add the remote repository using the owner as the remote name
git remote add $REMOTE_OWNER $REPO_URL
# Fetch from the remote repository
git fetch $REMOTE_OWNER
# Checkout and create a new branch tracking the remote branch
git checkout -b $BRANCH_NAME $REMOTE_OWNER/$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