Using Git with a Hosted Repository
READ ME FIRST
This article is provided as a courtesy. Configuration of third-party software is not covered by (mt) Media Temple's Statement of Support. Please take a moment to review the Statement of Support.
Setting up your repository
This KnowledgeBase article assumes that you already have your repository set up in Github. For instructions on using Github, please see the following guide:
Connecting via SSH
Once you have your Github or Gitlab repository configured, you can begin configuring Git on your Premium WordPress installation. Start by connecting to your Premium WordPress site via SSH:
Setting up Git
- Once connected, you can initialize Git using the following command:
$ git init
- Set your Github username and email address.
$ git config --global user.name "YourUsernameHere" $ git config --global user.email email@example.comTIP: If you don’t know your Github account email address, you can find it in Account Settings > Emails on Github
- Create your SSH key.
- Run the following command. Make sure to use your Github email address.
$ ssh-keygen -t rsa -C “firstname.lastname@example.org”
- You will be prompted for a location to save the SSH key. The default setting is the correct one, so simply press Enter at this prompt.
- You will be prompted for a passphrase, which you should enter, then press Enter. Nothing will show on the screen while you are typing, but it will take your input nonetheless.
- If successful, you will see some output confirming that the key has been saved, including a line similar to the following, which indicates the location of the public key file.
Your public key has been saved in /home/user1234567890/.ssh/id_rsa.pub.
- Print the key to your terminal using the ‘cat’ command. Be sure to use the actual location of the public key.
$ cat /home/user1234567890/.ssh/id_rsa.pub
- Copy the output. Add this to your Github account in Account Settings > SSH Keys > Add Key
- Run the following command. Make sure to use your Github email address.
Since (mt) Media Temple manages the core WordPress installation for you as part of the Premium WordPress service, you will only be able to use Git to manage plugins, themes, uploads, and other custom content. You will need to use a custom .gitignore file to prevent Git from attempting to write to the core WordPress files.
Start by opening the .gitignore file.
Add the following lines to this file. You can enter insert mode in vim by hitting the i key.
$ vim .gitignore
Exit insert mode by hitting Esc. Save and quit by typing :wq.
wp-admin/ wp-content/mu-plugins/ wp-includes/ wp-*.php !wp-config.php index.php gdconfig.php
- Add the remote repository to Git using the following command structure. Replace “username” with your actual Github username, and repo.git with the actual repository.
$ git remote add origin https://github.com/username/repo.git
- In order to make Git to work correctly, it’s best to tell it to use SSH.
- Start by editing .git/config.
- Look for the following section:
[remote "origin"] url = https://github.com/username/repo.git
- Navigate down to the url line with the arrow keys, and use i to enter Insert mode. Change it to match the following, where the email address is your Github email address and the username is your Github username.
[remote "origin"] url = ssh://email@example.com/username/repo.git
- Once this change has been made, exit Insert mode with Esc and Save/Quit by typing :wq
$ vim .git/config
- Finish by running the following commands:
git add . git commit -m “initial commit” git push -u origin master
- That’s it! You’re now ready to use Git!
This KnowledgeBase article is only meant to cover the initial set-up of Git on your Premium WordPress site. You can find additional information at help.github.com
Git is a free and open source, distributed version control system designed to handle everything from small to very large projects with speed and efficiency.
Git falls in the category of distributed source code management tools, similar to CVS, Subversion (svn), or Bazaar. Every Git working directory is a full-fledged repository with complete history and full revision tracking capabilities, not dependent on network access or a central server. Still, Git stays extremely fast and space efficient.
This article will focus on using Git with a subdomain on your Grid.
Before you start
This article has the following dependencies:
- Whenever installing third-party software, please consult the official documentation. (mt) Media Temple does not support the installation and configuration of software not installed at time of service activation. Please consult our Grid Scope of Support page for further explanation.
- The domain example.com is used as an example. Please be sure to replace this text with the proper information for your site or server.
- This article assumes that you have already set up Git locally on your own computer. Due to the diversity of desktop computer platforms, this article does not cover the steps to get it set up locally.
READ ME FIRST
This article is provided as a courtesy. Installing, configuring, and troubleshooting third-party applications is outside the scope of support provided by (mt) Media Temple. Please take a moment to review the Statement of Support.
The following Git packages are installed on the Grid:
These packages provide core Git functionality as well as the ability to browse repository information on the web and bridge Git with Subversion.
You can the following command to view the current version installed on your Cluster:
Creating a repository for use on your Grid subdomain
The normal workflow, when using Git, is saving your work to a local repository on your personal computer and, when ready for publishing, "pushing" those changes to your "bare" repository. Here are the steps needed for this process.
Remember that this article assumes your are using a Unix environment, such as OS X, on your personal computer. If you are using Windows, please substitute the usage of the following commands to match your local environment.
The following steps (1-6) are performed on your local machine:
- Add an alternate or subdomain to your service through the AccountCenter. For this article, we will use the descriptive name 'git.example.com'.
- On your personal computer, make a directory and create your bare repository.
mkdir example && cd example git init
- Now create a meaningless test file that we will commit to the local repository:
touch .gitignore git add .gitignore git commit -m "just adding test gitignore file"
- Create the "bare" clone named example.git:
Before we can push our local Git repository to the Grid, we have to create a bare clone. A default Git repository assumes that you'll be using it as your working directory, so Git stores the actual bare repository files in a .git directory alongside all the project files. Remote repositories do not need copies of the files on the filesystem unlike working copies. This is what "bare" means to Git -- just the repository itself.
cd .. git clone --bare example example.git touch example.git/git-daemon-export-ok
- It's now time to upload the repository to your Grid using scp. Please make sure ssh is enabled in the AccountCenter:
scp -r example.git firstname.lastname@example.org:domains/git.example.com/html/example.git
- Log into your Grid to complete the setup using SSH:
ssh email@example.com cd domains/git.example.com/html/example.git git --bare update-server-info cd hooks mv post-update.sample post-update chmod a+x post-update
Your repository is now configured!! At this point, you and your contributors will now be able to push and pull content to your new repository.
Using your repository
New users can clone your repository directly from the Grid to another machine using http with the following command:
git clone http://git.example.com/example.git
Now that we have a working repository both locally and on the Grid, we can start using git to "push" new content. Assuming you have added/updated new files locally you would use the following command to update your repository on the Grid from within your local example directory:
git push ssh://firstname.lastname@example.org/home/00000/domains/git.example.com/html/example.git master
Of course, this is a lengthy command to use every time you want to push your files. You can actually create a shortcut for the above using the Git remote add function. The following command matches up to the one above and uses the word "grid" as the shortcut name. Make sure you are in your local example directory first before running this command:
git remote add grid ssh://email@example.com/home/00000/domains/git.example.com/html/example.git
Now you can simply push using the command:
git push grid master
For more information about public Git repositories, see this page in the Git user manual.
For more information, see the INSTALL documentation for gitweb.