• Tracking and Staging Files
• Making a Commit
• Merge Conflicts
• Visual Editor
• GUIs for Git
Command-line interfaces (
Git is free to download. To install it on your computer you can download it for free here: 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.
1. Creating a 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 firstname.lastname@example.org
To learn how to create SSH keys on a Mac check out my tutorial on this. Alternatively, if you are using a Windows machine you can use the PuTTY client.
Once you are logged into the server you will need to navigate to the folder (your public HTML folder) where your WordPress application is installed.
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. 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.php
When you add a file to be tracked, it is considered to be “staged”. To
git reset HEAD
Or you can unstage a specific file:
git reset HEAD wp-config.php
3. Make a Commit
First, we commit the files we just added to be tracked.
git commit -m 'this is where the message goes'
We can also just commit all modified or deleted files in our installation.
git commit -a -m 'all the changes'
Next, we have to specify a remote depository (GitHub) that will be our origin.
The URL will be shown in GitHub under the depository’s Clone or download button.
When you commit specify a branch.
git push origin master
For example, here we a are pushing to the origin repository at the master branch.
If you did not specify a message in the push then the Nano Editor will show up.
git push origin master -m "message"
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. Pulling Changes from GitHub
To pull changes down from the GitHub repository use this command:
git pull https://github.com/GitHubUsername/git-repository.git
Sometimes pulling from a repository you may get an error message that reads “fatal: refusing to merge unrelated histories.” To correct this you will need to merge unrelated histories.
git pull origin master --allow-unrelated-histories
5. Merge Conflicts
Occasionally, when multiple people are working on a repository you will probably have merge conflicts.
Luckily, from the command line you can use a merge tool.
git config merge.tool vimdiff
git config merge.conflictstyle diff3
git config mergetool.prompte false
This will set vimdiff as the default merge tool. Next, we run the merge tool.
You can select to get changes from the Remote, Base, or Local. You
Next, save and exit from the merge tool visual editor. To save and exit
and then commit the changes and remove the extra files created by the diff tool.
git commit -m "message"
6. Visual Editor in Terminal
In addition to the merge
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.
To exit Visual Editor without making changes to the file, press Escape. The cursor will move to the bottom of the document. Then type:
To simply view the contents of a file in Terminal without opening Visual Editor type:
7. Git GUIs for Desktop
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.
8. 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