Table of Contents
- Introduction
- Terms
- Typical Workflow
- Setting Up a Repository
- Updating to Upstream
- Creating a Branch
- Committing and Pushing Changes
- Installing Git on Your Own Computer
- Common Problems
Introduction
Git is an important tool, both for the club and in the larger world of development. This is not an in-depth tutorial; rather, it discusses the basic steps needed to run git on the school computers.
Terms
- Repository (repo): A place where the history of your work is stored.
- Commit: When you have made changes to a repository and want them saved as part of its history, you commit these changes.
- Push: When you want to move your repository’s history to a repo hosted online (like one on GitHub).
- Fork: When someone branches their work off someone else’s to make their own changes. So, if an application I like has a blue background but I prefer pink, I could fork it and change the background.
- Branch: Essentially a fork within your own repository. It allows you to experiment or make changes without risking your
masterbranch. master: The main branch of a repo. In general, it is best not to make changes directly to it, but instead to use it to keep up to date with the upstream repository.- Upstream: A term for the repository from which you forked. Your repository is downstream from it because information flowed downstream to you.
Typical Workflow
- Set up a repository (only if not done previously)
- Updating to upstream
- Creating a new branch for your changes
- Making any changes
- Committing and pushing changes
Setting Up a Repository
-
Open the
Git Guiapplication -
Select
Clone Existing Repository -
Click on the white text box titled
Source Locationand paste in theHTTPS clone URLfrom your fork of the repo. Click theBrowsebutton next toTarget Directoryand choose a directory. -
Click at the end of the white target directory box. Type out the name of the repository.
-
Press the
Clonebutton and wait for the operation to complete. -
Click
Remote→Add. Fill in the name asupstreamand the location as the HTTPS clone URL of the club’s repo. Press the add button.
Updating to Upstream
-
In Git GUI, go to
Branch→Checkout...and selectmaster. -
Go to
Remote→Fetch from→All. -
Click
Repository→Git Bash -
Type the following commands:
git reset --hard upstream/mastergit clean -fdx
-
Go to
Remote→Push...and in the dialog selectmasteras the branch andoriginas the remote. -
Your repository is now up to date with upstream! From here, you should create a branch.
If you already made a branch by mistake, check out your branch (Branch→Checkout... and select your branch) and type the following command into Git Bash: git rebase master
Creating a Branch
- Click
Branch→Create. - Fill in a descriptive name for your branch under
Name. - Select
masterunderStarting Revision. - Make any changes to the branch and commit them.
- To switch between branches, go to
Branch→Checkout...and select the branch you want.
Committing and Pushing Changes
- Click the
Rescanbutton, and then theStage Changedbutton - Type a descriptive message in the large text box in the bottom half of the window (In the imperative present tense, e.g. “Add Player class”)
- Click the
Commitbutton - Go to
Remote→Push - Select the branch you want to push (probably not
master) - You should now go on Github and submit a pull request by clicking the green button with circular arrows on your repository’s page
Installing Git on Your Own Computer
Go to http://git-scm.com/downloads and download the right version for your OS. Installing should be pretty simple. Afterwards, open up the Git GUI application (on OS X and Linux, you may have to go to the command line and use the command git gui).
Additionally, on OS X and Linux, instead of going to Repository→Git Bash as on Windows, you just type those same commands into the command line.
Common Problems
Git says I don’t have permission to push to origin
This problem is due to your origin having been incorrectly set. It can be remedied through the command:
git remote set-url origin https://github.com/YOUR-USER-NAME-HERE/drugwars.git
Following this, attempt to push to origin and it should work.