This is how to copy your files from a given git branch to a new empty branch, using a squash merge.
This example will copy files from branch old-branch
to target-branch
# First be sure, that you don't have uncommitted working changes. They will be deleted
# Checkout a new empty branch without history
git checkout --orphan target-branch
# clear index and working tree
git rm -rf .
# Create empty commit
echo "Initial Commit" > test.md && git add test.md && git commit -m "Initial Commit"
# Merge the old branch to new one, using a squash
git merge --squash old-branch --allow-unrelated-histories
# Perform a commit, because the squash merge did not create a commit yet
git commit -m "sources from old repo"
Is there a difference between the posted code and this?
other than the
test.md
file, but as I understand it, that was created only to create an empty commit?