Git – How to deploy code from my central Git repo to my production server?

I’m new to Git. I need to setup Git to deploy a Django website to the production server. My question here is to know what is the best way of doing this.

By now I only have a Master branch. My problem here is that Development environment is not equal to the Production environment. How can I have the two environments(Development and Production) in Git? Should I use two new Branches(Development and Production). Please give me a clue on this.

  • Deploy a PHP project from Git to a server that does not have Git installed
  • Git deployment outside of heroku
  • Can't deploy generated Flask files using Git
  • git clone through ssh returns Permission denied (publickey,password)
  • Where to store differences between dev and production branch in git?
  • Repository deployment and Composer : what workflow?
  • Other question… when I finish to upload/push the code to the Production server I need to restart the Gunicorn(serves Django website). How can I do this?

    And the most important question… Should I use Git to do this or I have better options?

    Best Regards,

  • Control-C kills Ipython in git bash on Windows 7
  • How to INCLUDE lib files inside folder in a Git repository
  • Gitlab backup without repository commits
  • Git merge upstream branch
  • Do git update-index --assume-unchanged rules propagate to clients on pull?
  • Git - rebasing to a particular tag
  • 2 Solutions collect form web for “Git – How to deploy code from my central Git repo to my production server?”

    The first question you must solve is your project structure. Usually the difference between development and the production environment is setting.py and url.py. So why you firstly separate those? 🙂 For example you can have one main settings.py where you define all the default settings which are in common. Then at the end of the file you just import the settings_dev.py and settting_prod.py for exemple:

    try:
        from settings_prod import *
    except ImportError:
        pass
    
    try:
        from settings_dev import *
    except ImportError:
        pass
    

    Then simply you can overload all the setting you want and have custom settings of the project (for example installed apps). The same logic you can use for urls.py file.

    Then you can simply ignore adding the *_dev files to repo and on the server side you can just checkout the code from repo and restart http server. To automatize this for now I can’t give the right name of app to use. Sometimes simple python script could be solution like: watching if the file datetime changed and if yes, just run restart command for http.

    Hope that helped.

    Ignas

    You can follow this brunching model – http://nvie.com/posts/a-successful-git-branching-model/

    And, git is ok but use Fabric for deployment.

    Git Baby is a git and github fan, let's start git clone.