Git Cheatsheet - Getbeans/Beans GitHub Wiki

This cheatsheet is a handy companion to help you quickly get stuff done and contribute.

This guide assumes that you have git setup on your local machine, have a GitHub account, and have your local machine connected to your account via SSH.

Fork Beans

GitHub Documentation: Mac | Windows

The first step is to fork Beans to your local GitHub account. In doing so, you have your own copy of Beans and are free to work without affecting the official Beans repository (repo).

  1. Click on the "Fork" button in the upper right hand corner on this screen.
  2. Select to save it in your personal GitHub account.
  3. Wait a few seconds while GitHub copies it.
  4. Bam, you're ready to clone it.

Clone Beans

The next step is to get your copy of Beans from your GitHub account onto your local machine. Downloading won't cut it here as you need to sync everything up. That means you will be working in a command line app (like Terminal or iTerm on Mac).

  1. Go to your copy in your GitHub account.
  2. On the right hand side of the screen, there's a green button labelled "Clone or download". Click on that button.
  3. Click on the clipboard icon that's on the right hand side of the URL. Now you have a copy of the URL.
  4. Open up your favorite command line app.
  5. Navigate to your project's wp-content/themes/ directory.
  6. Then type git clone , paste the URL link you copied earlier, and then tm-beans.
  7. Press return or enter on your keyboard.

Git is now cloning the repository to your machine.

When it's done, you now have a local copy of the Beans repository on your computer. This is where you will develop.

Sync to Official Beans repo

You always want to make sure both your local and personal GitHub copy of Beans are up-to-date (sync'd) with the official Beans repository.

You need to setup the upstream "remote" on your local machine. This creates a link between your machine and the official Beans repo.

In the folder where you cloned the repository above, do these steps:

  1. Type:
git remote add upstream https://github.com/Getbeans/Beans.git
  1. Press enter/return on your keyboard.
  2. When Git is done, you can check that everything loaded by doing:
git remote -v

Here's what mine looks like:

$ git remote -v
origin  [email protected]:hellofromtonya/Beans.git (fetch)
origin  [email protected]:hellofromtonya/Beans.git (push)
upstream        https://github.com/Getbeans/Beans.git (fetch)
upstream        https://github.com/Getbeans/Beans.git (push)
  • origin is a binding to my personal GitHub Beans repository.
  • upstream is the official Beans repository.

Whew, you have everything wired (linked) together now.

Creating a Branch

TIP Never develop in master or development branches. Never ever ever.

All development work occurs in a branch. If you are working alone on a feature, then you will create a branch on your local machine, check it out, and then get to work.

GitHub Documentation: click here

  1. Make sure you are on the development branch.
  2. Think about a name you want to give to your branch. It should be named by the feature, bug, or issue that you are working on. Not sure? Reach out and ask us.
  3. In your command line app, type:
git checkout -b name-of-your-branch

What just happened? Git created a new branch for you, checked it out of version control, and switched you to it. You are now on your new branch.

What does that mean? Any changes you make on this branch will not affect any other branches. You are safe to develop, test, and debug without impacting anyone else.

Fetch Changes From Upstream (Official Beans Repo)

Lots of people are contributing to Beans. Therefore, the codebase will get changed while you are working on your branch. You need to keep your local (on your computer) and remote (your copy in your GitHub repo) up-to-date.

When the main development branch on Beans (upstream) changes, you can fetch and merge those changes by doing the following:

  1. Make sure you add any changes on the branch you are working on into git by typing:
git add .
git commit -m 'Fixed something cool'
  1. Now checkout the development branch
git checkout development

Not sure where you are? You can type git branch and it'll give you a list of your branches. The one with the * next to it and highlighted is the current branch on your machine.

  1. Time to fetch the latest changes from the official Beans repository
git fetch upstream
  1. When it's done, it's time to merge those changes.
git merge upstream/development

What's happening? The new changes from Beans (upstream) are being merged into your local development branch.

When it's done, your development branch is up-to-date.

A shortcut is to use git pull upstream development. git pull combines git fetch and git merge all into one command.

  1. Now it's time to get your remote copy of Beans up-to-date. Huh? remote means the copy in your GitHub account (on GitHub and not on your local machine). It's the remote origin you saw above when you typed git remote -v.
git push origin development

You may need to enter your passphrase. What's happening? Git on your computer is pushing your development branch to GitHub. When it's done, your copy of Beans in your GitHub account will be up-to-date.

Checkout a Branch

Work is done in a branch.

git checkout <name-of-the-branch>

For example, if you are working on a branch called fix-issue-xyz, you'd type:

git checkout fix-issue-xyz

Keeping Your Branch Up-to-Date

The development branch is being updated frequently as Pull Requests are approved and then merged. You want to keep your feature branch up-to-date often to ensure you have the latest changes and to minimize merge conflicts.

Step 1: Update your development branch

Pull the latest code from the Beans repo's development branch to your local machine by doing:

git checkout development
git pull upstream development

Step 2: Rebase Development to Your Branch

To update your feature branch with the latest code from development, do the following:

git checkout <name-of-your-branch>
git rebase development

For example, let's say your branch is named tests/api/html, then here would be the commands:

git checkout tests/api/html
git rebase development
  • The first commands checks out your branch and moves the HEAD to point to the last commit on that branch.
  • The next command updates your branch with the latest changes from development.