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:
- 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
-
-
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 getIdentity 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.
-
-
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
-
- Create .git file inside public_html and pointing it to .git folder. Example .git file:
-
gitdir: /home/grigliac/.git
-
- 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
-
- Now you can push pre to Production after Release.
- After push, login to Production SSH. and run:
$ git checkout -f master
- Should be Release before push to production