My Git Workflow
2 min read hello world git · hub · workflowWorking on a large team of developers can be difficult when trying to keep code, branches, and repositories in sync. Here are a few things that I have found helpful.
- Branch from master
- If you are using a ticketing/bug-tracking system, use the ticket/bug identifier in the branch name
git checkout -b ticket-1234
- Keep your branch up-to-date by syncing master to it frequently
git fetch && git merge master
- Commit to your branch frequently. The smaller you keep your changes, the safer it is to do this.
git commit -am "some really small change"
- Push to your remote Git repo as soon as you have a viable MVP (AKA something that doesn’t break)
git push origin ticket-1234
- If you are in the Github ecosystem, use Hub to submit your pull-request
hub pull-request
- After your P/R is accepted, remove it from the remote repository
git branch --merged master | grep -v master| cut -d/ -f2- | xargs -n 1 git push --delete origin
- Then remove it from the local repository
git branch --merged master| grep -v master | xargs -n 1 git branch -d && git update-ref -d refs/origin/master
Now, some may argue that syncing with master frequently leads to merge-conflicts. My response:
Conflict is a fact of life. Get over it. ~ Me
Seriously, the longer you wait to the address merge conflicts, the worse the process becomes. Several small updates are a lot less painful than one long update that can take hours to unravel depending on the size of the changes and the size of your team.
NOTES:
- Steps 7 and 8 are indiscriminate. They remove any branch merged with master. You may need to update those commands to delete only your branches
- If you are removing a merged branch that you do not have locally use this instead
git branch -r --merged master | grep -v master| cut -d/ -f2- | xargs -n 1 git push --delete origin
. - Leverage Unit Tests to ensure everything remains stable as you merge and push.
comments powered by Disqus