WPEngine + Git

Table of Contents

What is Git?

Git is a version control system that keeps everyone on the same page. It records changes to files which allows creating different branching versions and the ability to rollback to specific versions.

This is helpful when working with multiple people, making the code-base consistent for everyone. It can flag if the same code has been modified by multiple people, preventing conflicts, since we will be working locally (not directly on the live site files thru ftp).

Download and install git:
https://git-scm.com/book/en/v2/Getting-Started-Installing-Git

Generating SSH Key

Follow the steps here to generate the SSH key and add to wpengine portal https://wpengine.com/support/git/

.gitignore

.gitignore file specifies which files should only be included. We only want to include the files that we are changing. 

Create the .gitignore file on the root directory of your project.

Most of the time we only need to include the theme folder, in some cases you might need to include specific plugins or other files and folders outside of wp-content.

				
					# exclude all files
/*

# include the .gitignore file
!.gitignore

**/.DS_Store
**.log

!wp-content
wp-content/*

# include all themes
!wp-content/themes/

# exclude all default wordpress themes
wp-content/themes/twenty**
				
			
Other example rules:
				
					# include only a specific theme
!wp-content/themes/
wp-content/themes/*
!wp-content/themes/THEME_TO_INCLUDE

# include a specific plugin
!wp-content/plugins/
wp-content/plugins/*
!wp-content/plugins/PLUGIN_TO_INCLUDE
				
			
Git Status

Working with git

Initialize git

On the root folder of your project, open the terminal and enter:

				
					git init
				
			
Git Init 2

Connect your git project to the wpengine install git remote url

Get the wpengine install git remote url from WPEngine Portal > Project Install > GitPush

Git Wpengine Remote Url 2

Add the wpengine install git remote url as destination

				
					git remote add {project_name} {remote_url}

e.g:
git remote add nerve-centre git@git.wpengine.com:nervecentre5x5.git
				
			

Pushing your codes to live/wpengine

Add the list of file changes

				
					git add *
				
			

Commit the file changes, enter

				
					git commit -m "descriptive message here"
				
			

the message is required

push the changes to get / wpengine git repo

				
					git push
				
			

On your first push, you will be prompted to set the destination of where to push to, enter

				
					git push --set-upstream {project_name} master

e.g: 
git push --set-upstream nerve-centre master
				
			

Pulling changes from repository

				
					git pull
				
			

New dev init + pull shortcut

				
					git init
git remote add production git@git.wpengine.com:{install_name_here}.git
git pull production master
git branch --set-upstream-to=production/master
				
			

Share This

Select your desired option below to share a direct link to this page.
Your friends or family will thank you later.