Xamin

How to setup GIT on Production

How to setup GIT on Production

Setup GIT on production is depned on SSH key. Your cPanel should have SSH acces. Please follow the steps bellow:

  1. Generate SSH key on Cpanel
    • Goto <domainname>./cpanel

    • Goto SSH Access→Manage SSH Keys→Generate a New Key
    • Name the ssh key as <username>_ssh_key; Save the password on lastpass and generate
    • Authorize Public Key
    • Download Private Key
  2. Add SSH key on Local
    • Save private key on your local .ssh folder. MAC .ssh folder: /Users/<your_username>/.ssh. Windows .ssh folder: C:\Users\<your_username>\.ssh
    • Open Terminal and type
      $ ssh-add ~/.ssh/<username>_ssh_key
      Example
      $ ssh-add ~/.ssh/griglia_ssh_key
      After successfull add you should get
      Identity added: /Users/xamin05/.ssh/griglia_ssh_key (/Users/xamin05/.ssh/griglia_ssh_key)
      If you receive this:
      Permissions 0666 for '/Users/xamin05/.ssh/griglia_ssh_key' are too open. It is required that your private key files are NOT accessible by others. This private key will be ignored.
      Fix the permission by this:
      chmod 0600 /users/xamin05/.ssh/griglia_ssh_key
    • Now you can login to production SSH from Local:
      $ ssh <username>@<domain name>
      Example:
      $ ssh This email address is being protected from spambots. You need JavaScript enabled to view it.
  3. Git folder setup on Production
    • Open Production file manager; Place .git folder to one level up from public_html folder
    • Open .git/config; Add worktree and receive. Example config file:
      [core] 
        repositoryformatversion = 0 
        filemode = false 
        bare = false 
        logallrefupdates = true 
        symlinks = false 
        ignorecase = true 
        worktree = /home/grigliac/public_html 
      
      [gitflow "branch"] 
        master = master 
      
      [receive] 
        denyCurrentBranch = updateinstead
  4. Create .git file inside public_html and pointing it to .git folder. Example .git file:
    1. gitdir: /home/grigliac/.git
  5. Adding Production GIT on Sourcetree:
    • Open Sourcetree
    • Goto Settings→Remotes→Add
    • Add Remote Name: Production
    • Add URL/Path. Example:
      ssh://This email address is being protected from spambots. You need JavaScript enabled to view it./home/grigliac/.git
  6. Now you can push pre to Production after Release.
  7. After push, login to Production SSH. and run:
    $ git checkout -f master
  8. Should be Release before push to production
Xamin • Xamin • Xamin • Xamin • Xamin • Xamin • Xamin •

Bring the ideas to live with us

Get a Free Quote