Command-line interfaces (
To use Git on your
Git is free to download: https://git-scm.com/
Recently, text editors have created a lot of support for Git. Both Adobe Dreamweaver and Microsoft’s Visual Studio Code support it.
It will also work in CLIs locally installed in other software running on your computer: I’m thinking of the CLI tool built into Desktop Server.
1. Setting up Git with an Empty Repository
Port 22 is the secure shell access (SSH) port for connecting to the remote server your WordPress application is hosted on.
Hence -p 22 (port 22) is the command we will use to make a secure shell access request to our website:
ssh -p 22 email@example.com
If you are using a service like cPanel, the username and password will be set up with the cPanel account. You can also create additional accounts in Cpanel in the Web Disk tool.
However, I do recommend using a Linux server and MacOS to create SSH keys to access and install Git on your remote server. (Anyways!)
Once you are logged into the server you will need to navigate to the folder (your public
Initialize Git in that folder.
Now, when using git there has to be an origin source.
In GitHub, create a new repository that is empty. This will be where you will
We want that empty repository to be where we commit changes.
git remote add origin https://github.com/GitHubUsername/git-repository.git
Now you’re up and running.
2. Tracking and Staging Files
Do you want to track the status of every file in WordPress? Probably not.
Navigate to the WordPress folder you want to track commits in.
Once there, run a git status to make sure all the files are being tracked that you want to establish version control for.
For example, it’s probably a good idea to watch problem plugins or child theme folders.
You can either add all the files in the current folder
git add .
or specify specific files.
git add wp-config
3. Make a Commit
First, we have to specify a remote depository (GitHub) that will be our origin.
The URL will be shown in the depository’s Clone or download button in GitHub.
git remote add origin https://github.com/GitHubUserName/git-depository.git
The initial commit should be to this origin on the master branch.
git push -u origin master
Often times in command-line this will bring up the Nano Editor.
Type a message in the top of the Nano Editor above the commented out stuff to leave a message about what this commit is about.
Depending upon your setup you can then write out (
Write out and quit requires you to hit escape to bring the cursor to the bottom of the message. When it does, type
4. Tracking Modified Files and Pulling Changes from GitHub
Once you are tracking files git will keep track of added, deleted, and modified files.
When you run a git status it will show these files separate from untracked files.
At this point you have a decision to make. Do you pull down changes from your GitHub repository first or commit the changes on the current installation and push them to the GitHub repository.
To pull changes down from the GitHub repository use this command:
git pull https://github.com/GitHubUsername/git-repository.git
To commit changes from the currently tracked files type this command:
git commit -a
Using branches is the real strength of git.
Branching enables us to have different versions of our WordPress website’s plugins and files.
A pull request then enables us to merge successful modifications into our master version.
It’s also always a good idea to make sure if you are using multiple branches that you know what branch you are actually in.
If you are using branches, make sure to check out the differences between them. The git branch command will list the branches.
The git checkout command will take you to that branch.
git checkout master
Were files modified? Run the git diff command to find out.
Are any of these files staged?
git diff --staged
6. Git GUIs for Desktop
Who cares right? You’re using command line.
Well if you are writing a lot of code you will care, but anyways…
Navigate to the folder where there is a file you want to open. (For example, I am using a CSS file).
The default editor for UNIX operating systems is the visual editor. It is invoked using this command:
Not saying you will never use it, but let’s take a look at some of the GUIs.
My personal favorite is SourceTree from Atlassian. Nothing like seeing everything big, bold, and colorful.
SourceTree can connect to multiple Git services like GitHub through API.
And obviously, GitHub Desktop.
I consider it a must-have if you are using GitHub. While the interface is not as bright as SourceTree it does work easily.
7. If all else fails 🙂
If something goes wrong and you want to erase Git from the folder where you installed it use this command:
rm -rf .git