HOW TO SETUP A GREAT GIT WORKFLOW
When working on a project with multiple people, it is best to setup a git workflow that everyone can follow. It allows for less merge conflict issues and ensures everyone’s working on the same issue. Here’s a step by step guide.
0. In this guide, I will be using:
— Main Organization GitHub Repository = repo
— Forked copy of the Main Organization GitHub Reposition = fork
1. Fork the repo.
..Go to the main organization github repository (repo) page (in this example, Dage Team’s dage repo) and fork a copy of the repo.
2. Download the forked copy from GitHub to your computer.
..Using your favorite command line interpreter (bash/terminal/command line), download the fork with the command
— git clone https://github.com/gtdeng/dage.git
..Notice here, I am downloading my copy and not the organization’s repo.
3. Add an upstream remote branch.
..Doing this will facilitate pulling down new changes from the main organization repository (repo).
— git remote add upstream https://github.com/DageTeam/dage.git
4. Make a new sandboxed featureBranch.
..This allows you to make multiple changes to your branch and contain those changes to a different branch, thus isolating any damages you will do.
— git checkout -b ‘featureBranch’
5. Code! Start adding features to your codebase on the ‘featureBranch’
6. Commit those changes!
..Prior to making a commit, make sure your code works. Then run it through a linter and a testing suite (Jasmine, Mocha, Chai). If your code hasn’t broken anything, commit those changes by
— git add changedFile.js
— git commit -m ‘[feature] (server): add server side routing’
7. Add more changes to your code and repeat Step 6 until you’re ready to push changes back up to GitHub.
8. Push up to your GitHub fork.
..When you’re done making enough changes, you should push back up to your own GitHub fork (not the organization’s fork).
..I. First make sure you are currently in the ‘featureBranch’ then fetch all the new changes from the main organization repository (repo).
— git pull — rebase upstream master
..II. Then fix any merge conflicts that may occur.
..III. Continue rebasing.
— git rebase — continue
..IV. At this point, do one final style check and test check before pushing to your own fork. The following command will push all the featureBranch changes you have made to the master branch of your GitHub fork repo (not the org’s repo).
— git push origin featureBranch:master
9. Initiate a pull request
— Go to your fork’s repo and submit a pull request so that it can be merged to the main organization github repository (repo).
— At this point, the code should be able to be auto-merged (since the code passes all the test, it conforms to the style guide and you’ve fixed all the conflicts) and all the org repo master needs to do is to accept the pull request.
10. Sit back, relax, and bash in the glory of being a contributor of an open source project!