Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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