Skip to content

Simple Git Workflow guide

Mithi Sevilla edited this page Oct 3, 2020 · 3 revisions

Getting the code

Visual Git Reference

  • Fork the mithi/mithi-repository repository to your own account using the fork button on the top-right of the GitHub page.
  • Clone your repository ie:
    • git clone git@github.com:username/mithi-repository.git
    • git clone https://github.com/username/mithi-repository.git
  • Inside the directory, add upstream, ie:
    • git remote add upstream git@github.com:mithi/mithi-repository.git
    • git remote add upstream https://github.com/mithi/mithi-repository.git

Working on the code

  • git checkout master
  • Create a branch: git branch my-branch-name
  • Check out the branch: git checkout my-branch-name
  • Do your work and commit it to the branch
  • Make smaller commits rather than larger and don't commit in one commit things that are not logically connected
  • Squash commits it the commits are too small to prevent polluting the commit history
  • You can push your work to GitHub as often as you like: git push origin my-branch-name

Creating a pull request

  • Make sure that you committed all the work to your my-branch-name branch
  • Update your branch from upstream one last time
  • Push all the patches to GitHub: git push origin my-branch-name
  • Create a pull request against mithi/mithi-repository using the web interface in your account
  • If you have forgotten to get all the latest changes from upstream before pushing to your remote branch then you would see a message on github in the pull request about 'This branch is out-of-date with the base branch'. To fix, follow instructions on rebasing your local branch (below.) Then you have to force push to your remote branch (Blog Link): git push origin my-work --force
  • Wait for the request to be reviewed
  • If changes are requested, make the changes, commit them to your my-branch-name branch, and push the new commits to GitHub: git push origin my-work
  • Allow changes by maintainers to your pull request how?
  • Repeat until the request is merged (person merging should choose 'Rebase and Merge')
  • Delete the branch when merged git branch -D my-work

Updating your repository with upstream changes

If somebody else's (or yours) changes were merged to the main repo and you want your local repo to reflect them, do:

  • Fetch the changes from upstream: git fetch
  • Go to your local master branch: git checkout master
  • Rebase it: git rebase upstream/master
  • Push your local master to your GitHub: git push origin master

Please avoid doing git pull, having fetch & rebase workflow results in a more readable history.

You can and probably should update your current work branch too to avoid merge conflicts in your future pull request:

  • Checkout the branch: git checkout my-work
  • Rebase against your master: git rebase master
  • Work as before