Step 4: Deploying to a live server
For this article I’m going to cover a very basic deploy strategy that uses the master and origin branches. There are more advanced methods like Capistrano and multiple branches for staging and production that I will cover in future articles. See the Git Reference for more info on working with branches.
Moving to our live server were going to clone repo. This assumes the production environment lives on the same server as the remote repo or we have generated a working SSH key pair to access the remote repo.
cd {root public dir}
git clone ssh://git@remote_server_domain.com/home/git/project1 .
Now anytime you make updates SSH into the live server and run:
git fetch origin git merge origin master
If you ever need to rollback a change you can quickly do a git reset –hard your_sha. Your_sha represents a commit and to find the previous commit to roll back from run git log. This will output recent changes. Find the most recent “Merge remote branch” message and use the sha (long number after the commit message) to run your git reset command.
Conclusion
Hopefully this article gives you a basic understanding of how version control with Git works. This should give you a good start and keep you from wearing the “Pink Sombrero” I would love to hear how you use version control in your WordPress development workflow and welcome any comments or suggestions.
Resources used for this article:
- Help.GitHub.com
- Mark on WordPress: WordPress local dev tips DB & Plugins
- Clint Berry: Speed Up Your WordPress Development Cycle with Git
- WordPress.Stackexchange.com: Getting Started with Subversion, Git, or similar Version Control System to keep a History of my Files?
Hi,
Your steps work perfectly. BUT, how do I get back into the git user account to create new repos? What am I missing?
Thanks
Nvm… I figured it out. There are two ways (that I know of) to make new repos once bash shell access has been restricted.
1. People with sudo access use sudo su –shell /bin/bash git
2. People on shared hosting accounts can ssh into their main user account and then log into the”git” user account from another shell su -c ‘/bin/sh’ git
You should be aware of the environment variable GIT_SSH, which is used by git to find your ssh-speaking client, if ssh doesn’t work for you. The git install may be using plink.exe (via GIT_SSH) to perform the authentication. If so, make sure you have pageant.exe running, and the key you created for github loaded into it. This provides the key to plink.exe; without it, the above error will occur.