Skip to content

Git Workflow

Sergey Piterman edited this page Jan 21, 2016 · 8 revisions

Checklist

  • Did I create my work branch off of master (didn't cut new branches from existing feature branches)?
  • Did I follow the correct naming convention for my branch?
  • Is my branch focused on a single main change?
  • Do all of my changes directly relate to this change?
  • Did I rebase the upstream master branch after I finished all my work?
  • Did I write a clear pull request message detailing what changes I made?
  • Did I get a code review?
  • Did I make any requested changes from that code review?

General Workflow

###Make a fork Create a fork from the main repo to your github profile. Clone the repo to your machine from your fork. Do not clone from the main repo.

###Add a remote After pulling down the repo, add a remote: git remote add upstream [git url of the master repo]

###Make your own branch git checkout -b [name of your branch]

###Commit and rebase git pull --rebase upstream development

Writing and Committing Features

$ git checkout -b feat-branch upstream/development
Branch development set up to track remote branch development from origin.
Switched to a new branch 'feat-branch'
$ git branch -a
$ git pull --rebase upstream development
From https://github.com/mks-greenfield/trendr
 * branch            development -> FETCH_HEAD
Already up-to-date.
$ git add -A
$ git status
$ git commit -m "[feat] Add feature"
$ git pull --rebase upstream development
$ git push origin feat-branch
  1. Create a feature branch from master. git checkout -b [name_of_your_new_branch]
  • Prefix your branch name with what you are working on:
    • Example: feat-authentication
    • bug-...
    • cleanup-...
    • doc-...
    • feat-...
    • refactor-...
    • test-...
  • View all branches: git branch -a
  • To create a branch off a remote branch that is not master: git checkout -b [name_of_your_new_branch] origin/[name of remote branch]
  1. Commit every time you implement a working piece of your program. Try not to add 10 lines of code in 1 file and 20 lines in another unrelated file before committing once.
  2. To stage files to commit, you can cover your bases by using git add -A. However you can use any of the following:
  • git add -A: Stage all (new, modified, deleted) files.
  • git add .: Stage new and modified files only.
  • git add -u: Stage modified and deleted files only.
  • git add [filename]: Stage specific file.
  1. Use git status to verify that you've staged all files you wanted to change.
  2. git commit to add changes.

Managing Merge Conflicts w/ Rebase

  1. Commit your changes to your local branch
  2. Rebase from upstream: $ git pull --rebase upstream development
  3. Run git status to see what files have merge conflicts
  4. Handle merge conflicts within those files
  5. For each file you resolve the conflicts for: $ git add [filename]
  6. Continue the rebase: $ git rebase --continue
  7. Push to your branch on your fork: $ git push origin [branch name]

Resources

Clone this wiki locally