Skip to content

Instantly share code, notes, and snippets.

@juemura
Last active January 26, 2019 10:22
Show Gist options
  • Save juemura/f91ecd2b2e0ed8a77a84d25cdbe105ea to your computer and use it in GitHub Desktop.
Save juemura/f91ecd2b2e0ed8a77a84d25cdbe105ea to your computer and use it in GitHub Desktop.

A git workflow for working in teams


The everyday routine:

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. Fork the base repo.

Go to https://github.com/ORGANIZATION_NAME/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.

2. 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

3. Clone your repo:

Open your terminal and navigate to the folder where you want these files to be. Type git clone followed by the link we just copied. git clone git@github.com:YOUR_USER_NAME/REPO_NAME.git

4. Create a remote to upstream:

Go to https://github.com/ORGANIZATION_NAME/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:YOUR_ORGANIZATION_NAME/REPO_NAME.git Back in your terminal, type git remote add upstream and paste the link. git remote add upstream git@github.com:YOUR_ORGANIZATION_NAME/REPO_NAME.git


More Tutorials:

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