I'm searching at using git to handle version control for any WordPress project.

I routinely have a nearby version, an improvement version on the web server the client can access and test on after which an active version.

I'll usually develop in your area then push my changes to some repo around the server after which SSH in to the dev folder around the server and pull in the repo. When I wish to publish the alterations around the live site I SSH in to the live folder on the internet server and pull in the repo.

Here's my dilemma.

I would like the media put into the neighborhood version with the WordPress admin (image uploads etc) to become overlooked however i want media put into the Dev version to become monitored then when I pull towards the live site the media files in the dev site are drawn.

Any ideas on the easiest method to make something similar to the work?

There might be better methods to this, however these two options have labored acceptable for me in the same situation. Let us think that the branch you're employed on in your area is known as master and in most your databases the remote origin refers back to the bare repository that you simply push to.

  1. If all of your media fall nicely into one directory, you'll have a separate repository that tracks the media and include that like a submodule towards the dev and live databases. Inside your local copy, you need to either:

    • [within the situation in which you want the live media in your area] take care not to (a) commit inside your submodule, (b) push from this nor (c) give a latest version from the submodule for your master branch
    • [within the situation where you do not need individuals media whatsoever inside your local copy] not update and initialize the submodule whatsoever - just add its road to .git/info/exclude

    Even when your media have been in various sites you can still make use of this method, but controlling submodules is a little of the discomfort, and will get quickly more irritating for those who have plenty of them.

  2. Alternatively, you can preserve your dev and live databases on the different branch, say known as with-media, that is always just like master however with commits that add the media in the finish from the history. You are able to maintain this case with git rebase. For instance, if you have just made some changes in your area that you would like to push, you'd do:

    git push origin master
    
    ssh server
    cd dev
    # git branch should show you that you're on 'with-media'
    git fetch origin
    git rebase origin/master
    

    Now suppose you upload some files towards the dev repository, and wish to commit them:

    ssh server
    cd dev
    git add [whatever-media-files]
    git commit
    git push origin with-media
    

    How to improve your live repository, you can easily do:

    ssh server
    cd live
    # git branch should show that you're on 'with-media'
    git fetch origin
    git merge origin/with-media
    

    To setup individuals branches to begin with, you'd do:

    ssh server
    cd dev
    # git branch should show that you're on 'master', since you haven't created
    # the other branch yet:
    git checkout -b with-media
    git push origin with-media
    
    cd ~/live
    git fetch origin
    git checkout -t origin/with-media
    

    As you last note, suppose you do something about it within the dev repository that are not just adding media, and also you want individuals code alterations in your master branch. Then (before you decide to push anything!) you have to reorder a brief history with git rebase -i origin/master.

      ssh server
      cd dev
      git rebase -i origin/master
      # Reorder the lines so that the non-media commits are first (earliest) in the file.
      # Save the file and exit your editor.
    
      # Now find the SHA1 sum (object name) of the last commit that has non-media changes.
      # (The object name of the commits will have been changed by the rebase.)
      git log --oneline
    
      # Let's say that was commit f414f3l.  Then you can push just the history up to and
      # including that commit back to the master branch with:
      git push origin f414f3l:master
    
      # Also push your 'with-media' branch back:
      git push origin with-media
    

    In a perfect world you will not have to do individuals last steps frequently, but used it is good to understand how to do this :)