Get Git Again


I often have to write things out on paper, my whiteboard, or even diagram things in photoshop.  git was one of those things that I have to visually see the steps to fully understand it.  The diagram here might not apply to all scenarios, but if you are working with a staging and production branch it will keep things synched up.

This diagram also assumes that you are starting any new changes on the Staging branch, which you should always do.  So, staging is already checked out before you start coding.  If you work with others, you would also always do a git pull upstream staging to ensure that you have the latest of everything.

I have also learned that it is better to commit a lot of small changes that address a specific task than it is to commit several changes that span several tasks.

So, even a small style change might look like the following:

  • Open project, I currently use VS Code, but used to be in PHP Storm
  • In terminal, cd to the correct directory, if you didn’t open to it and make sure you are on ‘staging’
  • git pull upstream staging (assuming others might be committing changes, if just you, this step can be skipped, but I think it is good practice in case you do wind up working with others)
  • Make the request change.
  • Test in your local site – if good, proceed to the commit
  • git add –all
  • git commit -m “describe the change”
  • git push origin staging
  • In git, do a pull request, merge, confirm
  • Back in Terminal, git pull upstream staging
  • git push origin staging
  • git checkout master
  • git pull upstream master
  • git merge staging
  • git push origin master
  • In git, do a pull request, merge, confirm
  • Back in Terminal, git pull upstream master
  • git push origin master
  • git checkout staging (this is a very important step – Always go back to staging)
  • move on to the next request/change or close project.

One major thing to note, is that if you are working with others, you would want to test their code changes locally as well.  This is assuming that they are not already in production.

Now, I do have setups where I just have one branch and I even have setups with deploy scripts in place that automatically push code from git to production sites when a new commit is made, but they are sites where I am the only developer and I have rollback plans in place and they aren’t high risk sites…  BTW, to do this, I use DeployHQ integrated with my Flywheel account.  I wrote a little bit about here.