Skip to content
ns-echen edited this page Jul 23, 2015 · 8 revisions

Contributors

This git workflow description was forked from https://github.com/therewasaguy/p5con. Thanks for putting together this doc!

Ways to Contribute

  • Discussion --> Issues
    • Bug reports
    • Feature Requests
  • Code --> Pull Requests
    • Bug Fix
    • New Feature
    • Documentation
    • Example
    • Tests

Set up

  1. Fork, Clone, Configure Remotes, Install Dependencies - Fork https://github.com/NarrativeScience/lsi to your github account. - Clone your fork of the repo from Terminal:
    ``git clone https://github.com//lsi``
- Navigate to the newly cloned directory: ``cd lsi``
- Add a reference to the original repo as a remote called "upstream":
    <pre><code>git remote add upstream https://github.com/NarrativeScience/lsi</code></pre>
- Install Dependencies:
    <pre><code>
``virtualenv venv``
``source venv/bin/activate``
``pip install -r requirements.txt``
``python setup.py develop``</code></pre>
  1. Get Latest Changes - If you cloned a while ago, get the latest changes from upstream:
    • git checkout master --> switch to your "master" branch
    • git pull upstream master --> pull changes from the "master" branch of the remote repo we called "upstream"
  2. Create a new branch - git checkout -b <topic-branch-name>
    • -b creates the branch
    • checkout makes this your current branch. Updates all the files to reflect whatever’s in that branch
    • checkout -b does both at the same time.
    • This is a good idea in case your PR is not accepted right away, and you want to work on something else in the meantime. Because any commits you make to a branch with an unresolved pull requests will be added to the pull request.
  3. Commit Your Changes - git add <files you want to include> - git commit -m <your short commit message> - Commit messages should explain the change(s) you made. - If you have a messy commit history, you can use git rebase to tidy up before sending the pull request.
  4. Push To Your Fork - git push origin <topic-branch-name>
  5. Open Pull Request - GitHub info on Using Pull Requests - Clear description of changes, clear title, imperative tense (i.e. "fix bug")
  6. Discuss & Amend Pull Request - Pull Requests can be discussed, just like issues - Pull Requests are not static snapshots of your repo. They update whenever you add more commits to the branch, until the PR is accepted.

Useful Git Commands

  • git remote -v List all your remotes "verbosely"
  • git pull <name_of_the_remote> <branch_name>
  • git push <name_of_the_remote> <branch_name>
  • git checkout -b <topic-branch-name> Create a new branch and check it out
  • git stash Stash all uncommitted changes you’ve made to the branch. You can get them back later.
  • git log Show commit history.
  • git status Show branch and pending changes.
  • git diff View merge conflicts
  • git grep "something()" Search for things in your working directory.
  • git commit --amend Amend your previous commit rather than creating a new commit

Addendum:

Resolving Merge Conflicts:

  • Conflicts occur when branches have conflicting modifications that cannot be automatically resolved/merged. When you try to merge (i.e. pull upstream changes), if there are conflicts, git tells you and adds this stuff to your file:
<<<<<<< HEAD

Here is what you had locally
=======
Here is what was in the thing you tried to merge
>>>>>>> 59685c301d09b58fdac23d616

You can fix manually by picking which one you want and getting rid of all this: <<<<<< HEAD ======= >>>>> 583….