Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git: How to push dist directory to a separate branch of the same repository

I have a project in existing repository, the folder structure :

myproject (master)
+-- app/ (master)
+-- dist/ (in .gitignore, but i need it as other branch)
+-- node_modules (.gitignore)
+-- index.html (master)
+-- gulpfile.babel.js (master)
+-- package.json (master)

Is there a way to push dist to a separate branch of the same repository?
To clarify, I want only dist files in the deploy branch, and keep the another files in the master.

like image 262
vanio178 Avatar asked Sep 30 '18 03:09

vanio178


People also ask

How do I push a remote to a specific branch?

In order to push your branch to another remote branch, use the “git push” command and specify the remote name, the name of your local branch as the name of the remote branch.


1 Answers

Is there a way to push dist to a separate branch of the same repository?

There is, using git submodule.

  • create an orphan branch 'deploy'
  • copy your dist folder content in the empty repo, add and commit, and push.
  • add that branch as a dist folder submodule.

That is:

git checkout --orphan deploy
# copy your folder content
git add .
git commit -m "deploybranch folder content"
git push -u origin deploy

Then

git checkout master
git submodule add -b deploy -- /remote/url/of/your/own/repo dist
git commit -m "Add deploy branch as submodule"
git push

In your master branch, you will keep a reference to deploy through the dist root folder submodule.

That being said, keep in mind what is generated and deployed is usually not stored in a source control file system, but in a binary referential like Nexus or Artifactory: make sure you don't keep huge binaries in there.

like image 175
VonC Avatar answered Oct 03 '22 04:10

VonC