Skip to content

Instantly share code, notes, and snippets.

@msdousti
Created August 10, 2023 15:18
Show Gist options
  • Save msdousti/0a66cc8a9cdf9dae01414ab0933cf831 to your computer and use it in GitHub Desktop.
Save msdousti/0a66cc8a9cdf9dae01414ab0933cf831 to your computer and use it in GitHub Desktop.
#!/bin/bash
# Assign the first argument to branch_name,
# or use "new-branch" if no argument is provided
branch_name=${1:-new-branch}
# Set the branch variable based on existence
if git show-ref --verify --quiet refs/heads/master; then
branch=master
else
branch=main
fi
git checkout -b "$branch_name" "origin/$branch"
git cherry-pick $(git log --reverse --pretty=format:"%H" "$branch" "^origin/$branch")
git push -u origin "$branch_name"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment