简体   繁体   中英

Push a directory to one remote but not another with Git

I am using Git as part of my web development workflow. I have a hook that creates a backup of the database before a commit. I then push everything up to a master repo for backup purposes. Then when I'm ready I push everything to the live server. However I do not want the database backups to be pushed to the live server for security.

Is there a way to tell Git to not copy the database backups when pushing to the live remote but still have it push the database backups to the master repo?

I have a hook that creates a backup of the database before a commit.

Is this a local hook making local database backups?

Instead, you should make a database backup on a staging server in a post-update or pre-receive hook. This workflow might be suitable for one person, but you're going to have issues if someone else is committing sql dumps.

When you make the database dump in one of those hooks, don't put them in your git repo. Put them somewhere else on the file system. That way, your backups don't stay under version control.

A typical workflow will be:

  1. work locally and make some commits
  2. push your commits to remote
  3. remote hook makes backup of database

If you have two remotes, one for staging and one for production, all you have to do is push to staging to make your backups and push to production to deploy the live project.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM