I have a repo say A
and I want to add a new repo B in it using git subtree
From inside the repo A
, I can run the following command
git subtree add --prefix=.github/workflows <my-repo>.git master --squash
and the new repo is cloned inside .github/workflows
folder
Now I run some find and replace commands on .github/workflows
using sed
.
For this reason, it's important that it's a fresh git subtree add
so that my variables which need to be replaced are present.
So, I can do something like this
rm -rf .github/workflows/*
git subtree add --prefix=.github/workflows <my-repo>.git master --squash
sed -i '' -e 's/MY_LABEL/MYTAG/g' .github/workflows/*.yml
This will do the job, but it will unnecessarily create commits everytime I do subtree add. However, can this be achieved using just git commands (not using rm -rf)
I plan to use this in a pre-commit
hook so that it's always run before a user commits.
What's the correct way to do it?