Skip to content

Instantly share code, notes, and snippets.

@edburns
Created July 15, 2020 03:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save edburns/90ec0d633ba7ee06bef98c74e0cbb2e5 to your computer and use it in GitHub Desktop.
Save edburns/90ec0d633ba7ee06bef98c74e0cbb2e5 to your computer and use it in GitHub Desktop.
This gist copies the last N commits from sourceBranch to destBranch.
sourceBranch=$1
destBranch=$2
numLastCommitsOnPrivateBranch=$3
git checkout ${sourceBranch}
startingCommit=`git rev-parse HEAD`
endingCommit=`git rev-parse HEAD~${numLastCommitsOnPrivateBranch}`
git checkout ${destBranch}
ontoValue=`git rev-parse HEAD`
git rebase --onto ${ontoValue} ${endingCommit} ${startingCommit}
git rebase HEAD ${destBranch}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment