Pick our brains...

GIT: Setting up a client project under source control

The purposes of this how-to is to give detailed instruction on how to setup a client code project so that it can be used with source control via BitBucket. The same procedure can be used whether the codebase already exists or not.

By the end of this how-to you will have achieved the following things:

  • The client will have their own BitBucket account (if they don’t already).
  • The codebase will be safely tucked away in an appropriately labeled repository.
  • You will be able to push and pull changes from the GIT repo to the server
  • You will be able to push and pull changes from the GIT repo to you local machine


The following knowledge is useful to know for this how-to (but is not required):

Step-by-step guide

Important Pre-requisites:

  1. Find the client creds sheet.
  2. Open the cred sheet(s)… duh ;P
  3. Does the client already have a BitBucket account or not? Check the cred sheet(s) carefully. If not then please follow the steps in the “Creating a BitBucket account” section below.

Creating a BitBucket account:

  1. Go to http://bitbucket.org and click the “Sign Up” link.
  2. Enter FirstName as the full name of the client (eg. “Dolly Parton”).
  3. Enter Last Name as “(Web Apps)”.
  4. Enter a suitably unique username (eg. dollyparton_webapps).
  5. Enter a strong password (see https://strongpasswordgenerator.com/).
  6. Enter in the client’s Email Address.
  7. Choose “Personal Account” as the Plan.
  8. Answer the Captcha and click the “Sign Up” button.
  9. When prompted choose to “No Thanks” for the tutorial. You will now be logged-in as the client.
  10. ***IMPORTANT***: Record the Username, Email and Password in the client’s cred sheet under a new section titled “BitBucket Account (for projects under source control)”
  11. Everything recorded and saved? Now see section “Create a blank Repository for the codebase”.

Logging into BitBucket:

  1. Assuming you somehow got logged out of BitBucket in the previous section or the client already has BitBucket account you need to log-in to.
  2. Go to http://bitbucket.org and click the “Log in” link.
  3. Enter the BitBucket username or email.
  4. Enter the BitBucket password.
  5. Click the “Log in” button.

Create a blank Repository for the codebase in BitBucket:

  1. Assumption: You are logged into BitBucket as the client account.
  2. Under the “Repositories” pull-down menu in the top nav-bar choose “Create repository”
  3. Enter the Name as “{client_code} – {app_name}” (example: “PM – Peacefulmedia.com“)
  4. Enter a suitable Description. Describe what the app is and it’s purpose. Also where it will be hosted (or is hosted).
  5. Access level: This is a private repository
  6. Forking: Allow only private forks
  7. Repository type: GIT
  8. Project management: Issue Tracking & Wiki
  9. Language: Usually “PHP” (especially if WordPress)
  10. Click the “Create repository” button.

Setting up the “Server” (ie. where the app/site is hosted) and checking the codebase into GIT:

  1. You will need SSH access to the server where the app is hosted – check the cred sheet(s). The SSH username and password is usually the same as the FTP creds (but not always). You will be using an SSH client to log-in to the hosting account as the owner of the account (please don’t use root).
  2. There are a variety of different SSH clients for nearly all platforms (eg. on Windows use “PuTTy”). Pick one and learn the basics on how to connect to a server, set it up and save your settings (including password). “Coda 2” is a wonderful FTP/SSH client for Mac which I highly recommend.
  3. Assuming you want to stick to basics and just use command line – supported natively on Mac and Linux – then, from a Terminal/Shell window the command is: ssh username@hostname_or_ip (eg. ssh peaceful@peacefulmedia.com). Note that you can do this on Windows as well but you will need to install additional software (such as OpenSSH) and use Windows Powershell. You will be prompted for the SSH password – enter it.
  4. Once successfully connected you will see a command prompt (example: peaceful@peacefulmedia.com [~]#). This is where you can enter commands.
  5. Type ls -a to see all the folders/files. Locate the folder that contains the web application files – usually “public_html” on basic hosts, but not always.
  6. Type cd name_of_folder (eg. cd public_html)
  7. Type ls -a again. Is there a folder called .git ?? If so then you need to stop and talk to a developer. Otherwise continue.
  8. BitBucket: Navigate to the repository home by clicking the main “BitBucket” item in the top-left and then clicking the repository link on the Dashboard > Overview tab.
  9. BitBucket: In the top-right of the repository home there is a section that looks something similar to this:
  10. Make sure the first dropdown says “SSH” (not “HTTPS”) and then copy & paste the entire contents of the box on the right (starting withgit@bitbucket.org and ending with .git). Put this line in a text file somewhere. You will need it soon.
  11. On the server type the following commands to create the local GIT repository for the codebase:
    git init
    git config user.name "Peaceful Media"
    git config user.email "admin@peacefulmedia.com"
  12. More to come….


Scott Butterworth – More to come!! Have patience young padawan  (smile)



  1. Can you finish the rest of this one Scott? Super helpful so far (smile)

  2. Hey SB! I agree with Brian – this is super helpful so far and would love more instructions (smile)

    I’ve started the process to setup DCD with a repo:

    • I created a Bitbucket account for her and put the login creds in her cred sheet
    • I verified there isn’t a .git folder on her server

    Next – I need to add an SSH key to her account before I’m able to see the repo ssh/https path (see screenshot).

    Just to verify: I add my own SSH key, correct? I’m confused because I’m setting her account up to be used by Peaceful Media… So if I add my SSH key to identify my computer, than anyone else who wants to work on this repo would enter their SSH key. Just making sure I’m understanding correctly.

  3. Scott responded via email about this and some questions about the process. Copying that here for reference:


    *looks in mirror* Dang it Scott! You need to finish those instructions dude!

    Hi Crispin, i’ll try to flesh out that article a little better before 10pm tonight. Its really a tough thing to document because there’s like a hundred thing to just know about.
    What you should do depends on the situation. Is it a revamp of an existing LIVE site?
    Here’s what I do (assuming client has no source control):
      1. Create client BB account and repo for site
      2. Add in four permission groups on client BB account (Administrators – admin, Developers – write, Viewers – read, Blocked – no access)
        • CB: go to the profile icon upper right/Manage Account/User Groups
      3. Add my BB username to the Administrators or Developers group. Now since I have my SSH key tied to my own BB account I can access the client’s repos by proxy via my own BB account.
      4. SSH into server with the latest and most up-to-date version of the WP site – and set up the usual crap… add myself to ~/.ssh/authorized_keys (CB: make sure it’s set to 600 for permissions), create a couple of SSH keys for use with BB plus a default id_rsa keyset, add in WP-CLI, etc
        • id_rsa_bitbucket_master
        • id_rsa_bitbucket_deployonly
        • id_rsa
      5. Go into site folder and do a git init then edit the .git/config file and add in the remote section to connect to the BB repo – or issue a git remote-set. I prefer to just edit the file.
        • CB: git remote add origin git@bitbucket_master:client_webapps/clienthttp://capes-lauracapes.com.git
        • make sure it’s “bitbucket_master” not “bitbucket.org.
        • This matches the Host in the config file you set up for the SSH keys above
        • .ssh/config example:
            • Host bitbucket_master
              HostName bitbucket.org
              IdentityFile ~/.ssh/id_rsa_bitbucket_master
              User ssh-user-nameHost bitbucket_deployonly
              HostName bitbucket.org
              IdentityFile ~/.ssh/id_rsa_bitbucket_deployonly
              User ssh-user-name
      6. Add in a .gitignore file tht ignores a ton of the stuff you want to ignore for a WordPress site. See the .gitignore on the sites on elevatethemedev.com for an example of what to put in ignored. I usually allow most of the active plugins to be checked into the repo – its just easier and more useful for deployments.
      7. Once the .gitignore is created do a git add -A . then a git commit -am “Initial commit (v1.0)”
      8. Add the server bitbucket SSH key to the client BB account under Account Settings > SSH keys
      9. Since this is an initial push from an existing WP site to a new repo you can use: git push -u origin –all
      10. Then do a git fetch then git pull to make sure downstream GIT is functioning
      11. Use wp-cli to create a database backup (wp db export) and you can transfer it from the server to your machine via either FTP or SCP (I use SCP). You can use wp-cli on your machine to restore it (wp db import) then replace the url via search-replace (wp search-replace).
    Now just kinda repeat most of that stuff (from step 5 onward) above on your local machine. You DO NOT need to add your machine’s SSH key to client BB since you an Administrator on the account, just use the SSH connection to your own BitBucket account. Voila
    I make sure that the DEV site and LIVE sites are all setup correctly to push/pull from BB too. I usually use a separate folder on LIVE if there’s an existing site already running that we will be replacing – so I dont conflict or risk wiping out their current site.
    To answer your questions:
    1. Develop locally or on DEV, or both, I do CSS and PHP changes locally and content changes on DEV. I use scripts to pull database from DEV to local on demand.
    2. Once you are ready to go live then your DEV site will be fully up-to-date. You can use GIT to deploy the file changes to the LIVE server. The DB changes you should deploy via wp-cli (export on DEV then transfer and import on LIVE)
    3. I don’t usually bother with maintenance mode since I just deploy the changes with GIT and the whole wp-cli phase for the DB takes me like 2 mins.
    Scott ButterworthSr. Developer