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.
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).
- Click on the "Fork" button in the upper right hand corner on this screen.
- Select to save it in your personal GitHub account.
- Wait a few seconds while GitHub copies it.
- Bam, you're ready to clone it.
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).
- Go to your copy in your GitHub account.
- On the right hand side of the screen, there's a green button labelled "Clone or download". Click on that button.
- Click on the clipboard icon that's on the right hand side of the URL. Now you have a copy of the URL.
- Open up your favorite command line app.
- Navigate to your project's
- Then type
git clone, paste the URL link you copied earlier, and then
enteron 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:
git remote add upstream https://github.com/Getbeans/Beans.git
- Press enter/return on your keyboard.
- 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)
originis a binding to my personal GitHub Beans repository.
upstreamis the official Beans repository.
Whew, you have everything wired (linked) together now.
Creating a Branch
TIP Never develop in
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
- Make sure you are on the
- 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.
- 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:
- 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'
- Now checkout the
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.
- Time to fetch the latest changes from the official Beans repository
git fetch upstream
- 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
When it's done, your
development branch is up-to-date.
A shortcut is to use
git pull upstream development.
git mergeall into one command.
- Now it's time to get your
remotecopy of Beans up-to-date. Huh?
remotemeans the copy in your GitHub account (on GitHub and not on your local machine). It's the remote
originyou 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
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
HEADto point to the last commit on that branch.
- The next command updates your branch with the latest changes from