xxxxxxxxxx
## Moving to an existing branch
git checkout existingbranch
git merge branchToMoveCommitFrom
git checkout branchToMoveCommitFrom
git reset --hard HEAD~3 # Go back 3 commits. You *will* lose uncommitted work.
git checkout existingbranch
xxxxxxxxxx
# Note: Any changes not committed will be lost.
git branch newbranch # Create a new branch, saving the desired commits
git reset --hard HEAD~3 # Move master back by 3 commits (Make sure you know how many commits you need to go back)
git checkout newbranch # Go to the new branch that still has the desired commits
xxxxxxxxxx
# Clone the repository
git clone https://github.com/username/repo.git
# Navigate into the repository
cd repo
# Create and checkout a new branch
git checkout -b new-branch
# Cherry pick the commits you want to move
git cherry-pick commit-hash1
git cherry-pick commit-hash2
# Verify that the commits are cherry-picked properly
# If everything looks good, push the changes to the new branch on GitHub
git push origin new-branch
# Finally, delete the cherry-picked commits from the original branch (optional)
git branch -D original-branch
git push origin :original-branch