Search code examples
gitversion-controldev-to-production

How to maintain old files in git, (but not in production)


I have a git repository, and I'd like to keep some files in source control, but not in production, (my master branch represents production). Ideally, I think, I'd like to have a local folder called 'backup' that was pushed to GitHub, but not production.

Example
Production server should have: june.png
GitHub should have: january.png, february.png, march.png, april.png, may.png june.png july.png (etc)

My goals are to minimize the size of my production footprint, and to avoid having back-up files accessible by url (/images/january.png).

How should I accomplish this?


Solution

  • Whatever you committed will never be lost in git.

    Just add a new commit which deletes all old files no longer needed for production.

    If you ever want to see those files just checkout the old version and you are done.

    You can even specify a time:

    git co master@{yesterday}
    

    or

    git co master@{January}
    

    This will show you all the files at the given time.


    If you explicitly want another version of your project with those files deleted, use a new branch, delete the files there and later merge from the other branch to include any changes done there.

    git branch -m production
    git rm $files
    git commit -m 'delete old files'
    git push -u origin production
    git checkout master
    # update project
    git commit -am 'introduced cool feature'
    git push origin master
    git checkout production
    git merge master
    

    This way master has all the files for github and production the old files removed. As long as you do not start changing the old files the merge from master to production should cause no conflicts.