I have my local Git repo which I push and pull to Github with my team as a central repo.
I then have a remote staging area which has the whole bare repo and post-receive hook to push my changes to the web. I use 'git push staging master' for this which puts site to staging area.
My project consists of a src/
directory which I use to store my gulp files and sass files. I then use gulp to compile and produce my dist/
directory.
I obviously don't want my dist/
stuff in the Github repo as this causes crazy conflicts and doesn't need to be there, but I do want it in my remote website repo for production. How do I go about doing this?
I've looked at setting up separate .gitignore
files for each remote, but this doesn't make sense as it almost defeats the point of Git, and I also don't think it's even an option after I googled a little.
While your question is a little broad, here's a baseline you could start off of.
You want to always ignore the dist
directory and make the server (staging or prod) trigger a npm install
after it has checked out the latest version.
Also, if you are using yarn or npm v5, commit the yarn.lock
or package-lock.json
file that it generates.
Then, make it trigger your gulp build
with npm's post-install
hook.
You could also use husky, a npm module which automatically installs itself in the .git
directory, letting you define and version git hooks based on commands in the scripts
attribute of the package.json
.
"scripts": {
"postcheckout": "npm install", // <-- Git hook from Husky
"postinstall": "gulp build" // <-- default npm hook
}