Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Keep specific files of two Git branches in-sync

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.

like image 902
idleberg Avatar asked May 31 '14 09:05

idleberg


People also ask

Does switching branches change files?

When you switch branches, files that are not tracked by Git will remain untouched. Since Git does not know about new_file.


1 Answers

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).

like image 110
VonC Avatar answered Oct 08 '22 04:10

VonC