Skip to content

Instantly share code, notes, and snippets.

@corkupine
Created August 4, 2023 14:19
Show Gist options
  • Save corkupine/5c32a94330437e3b0e5eb047994a5c04 to your computer and use it in GitHub Desktop.
Save corkupine/5c32a94330437e3b0e5eb047994a5c04 to your computer and use it in GitHub Desktop.
Duplicate all code on another branch with a commit with the diff
#Start out on the branch with the code we want
git checkout branch_a
#create tmp branch same as branch_a (so that we don't change our local branch_a state during the operation)
#working directory has all the code that we want, on tmp branch
git checkout -b tmp
# Change the branch head to the branch we want to be on. All the delta
# between the current source code and branch_b is now staged for commit
git reset --soft branch_b
# Move away from tmp, so our commit will go directly to branch_b
git checkout branch_b
# Now you can examine the proposed commit
git status
# Add the delta we want to the branch
git commit
# Sanity check that the branches have the same content now (should return an empty line)
git diff branch_A..branch_b
# Remove tmp, we don't need it anymore
git branch -D tmp
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment