I have a repository consisting of four files in the master branch: two project files (PHP files btw) plus a README.md
and .gitignore
. I would like to create an additional branch, that consists of just the two PHP files at the same commit-level. What's the best practice to keep those two branches in-sync, if possible I would like to commit once only to update my PHP files?
The reason why I'm looking into this, is that I would like to create a branch called dist, that only comes with the essential files.
When you switch branches, files that are not tracked by Git will remain untouched. Since Git does not know about new_file.
Create your dist
branch, recording the deletion of the files you don't want.
git checkout master
git checkout -b dist
git rm .gitignore
git rm README.md
git commit -m "Remove non-dist files"
Then, each time you want to update your dist
branch, simply rebase
it:
git checkout dist
git rebase master
That replay your dist
commit (which you made when you created that branch, and where you git rm
some files) on top of master
, which means it will always remove the extra files.
You will have to force push it to your remote, but that isn't an issue since nobody is supposed to contribute on that branch.
That being said, release management is generally not maintained through branching, but with a script able to package and release from the sources (meaning here one script in the master
branch that you execute in order to copy what is needed to where you want to deploy).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With