Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save juemura/c354421701cd9d8c1e934f4c0932f4cb to your computer and use it in GitHub Desktop.
Save juemura/c354421701cd9d8c1e934f4c0932f4cb to your computer and use it in GitHub Desktop.
Instructions to get started with git and GitHub for Mission Bit - Android Game Design 101

A git workflow for working in teams



The everyday routine

First make sure you're on your master branch. (git checkout master)

1. Fetch and merge code from the base repo to your local environment:

$ git pull upstream master

2. Update your remote repo:

$ git push origin master

3. Checkout a branch (use -b to create a new branch):

$ git checkout -b branch_name

4. Code away...
5. When you're done, stage the files that you modified using:

$ git add file_name or $ git rm file_name

Tip: use git status to see which files you modified, then just copy and paste them. If using Cloud9, you can click on each file that appears when you type $ git status and select git add

Important: Don't use $ git add .!

6. Commit your changes:

$ git commit -m "Brief description of changes"

7. Pull from upstream again to make sure you have the most up-to-date code.

$ git pull upstream master

8. Push your changes to your remote repo:

$ git push origin BRANCH_NAME Note that you must use the name of the branch that you are working on here. If you are working on branch_A and you type git push origin master, you're likely to see something like "Everything up-to-date." That's because your changes were made on the branch you created, and your master hasn't been altered.

9. Send a pull request (PR):

Go to https://github.com/YOUR_USER_NAME/REPO_NAME and you will see a prompt to send a PR right above the file directory. Follow the instructions on the screen.

Tip: When sending a PR, add notes about what you want reviewers to pay attention to, ask questions, note limitations, and feel free to annotate your own code. Whenever pertinent, add screenshots and explain the program's desired behavior. Read more about PRs

10. Do a little dance and ask a friend to review your code before merging it.

Code reviews and merges

If you're an admin in one of your organization's repo, you should receive an email notification whenever someone sends out a pull request.

1. Commit your own work first.

In your local environment, commit your changes before pulling your friend's code (no need to push, though you can).

2. Open the PR.

You'll find a link in the email, but you can also go to the base repo page >> Pull Requests

3. Pull and test in a separate branch.

Follow the command-line instructions onscreen to pull the code locally. They will be available on the "Conversation" tab, just above the box where you can enter comments. These instructions will look like this:

Step 1: From your project repository, check out a new branch and test the changes. $ git checkout -b YOUR_FRIENDS_USERNAME-BRANCH_NAME master $ git pull git://github.com/YOUR_FRIENDS_USERNAME/REPO_NAME.git BRANCH_NAME

This will pull your friend's changes into a separate branch, so you can test their code without having it interfere with your own. Once you're done testing, you can delete that branch using $ git branch -d BRANCH_NAME and go back to your work with $ git checkout BRANCH_THAT_YOU_WERE_WORKING_ON

4. Add comments and/or merge.

If you have suggestions or requests, add comments, inline and otherwise. If there are conflicts, github will not let you merge. Either click on Resolve conflicts or comment on the thread asking your friend to pull from upstream and resolve the conflicts. Note that, when your friend make any changes and pushes from that same branch, the PR will be updated automatically. If everything looks good, follow the instructions on the screen to merge. In other words, if there are no conflicts, there should be a big green button that says Merge pull request. Click that and confirm the merge.


The setup

1. Local git configuration settings

First things first! Configure your machine with your GitHub user

  1. Open Terminal.
  2. Enter git config --global user.email "your_email_address@your_email_server.com"
  3. Enter git config --global user.name "your_name" To learn more, check out Setting your email in Git
2. Fork the base repo.

Go to https://github.com/MissionBit/REPO_NAME and click Fork on the top right. Wait. When the forking is done, you'll be redirected to your remote repo, which is a copy of the base repo you just forked.

3. Copy the link to your remote repo:

From your remote repo (the address bar will display https://github.com/YOUR_USER_NAME/REPO_NAME, find a green button that says "Clone or download." Click this button and copy the link, which will be something like: git@github.com:YOUR_USER_NAME/REPO_NAME.git

You can either use HTTPS and enter your username/password everytime you push, or you can configure ssh access. If you choose the latter, remember to revoke the Mission Bit computer access after the end of this class.

4. Clone your repo:

Open your terminal and navigate to Desktop > Projects. Type git clone followed by the link we just copied. git clone git@github.com:YOUR_USER_NAME/REPO_NAME.git

5. Create a remote to upstream:

Go to https://github.com/MissionBit/REPO_NAME and find the green button that says "Clone or download." Click this button and copy the link, which will be something like: git@github.com:MissionBit/REPO_NAME.git Back in your terminal, type git remote add upstream git@github.com:MissionBit/REPO_NAME.git. Hit enter.


More Tutorials

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment