A simple git workflow

Calvin Ho
2 min readAug 9, 2021

Git can be daunting to beginners, and it took me awhile before I got comfortable with a lot of the commands. I am assuming you have cloned your repository to your local machine. Here is the workflow that I use:

Git workflow for new branch

  1. Create an issue on GitHub
  2. Update local main branch: git checkout main && git pull
  3. Create a branch with the format issue_number-description (e.g., git checkout -b 42-new-branch
  4. Make your changes and stage them (e.g., git add newFile.js )
  5. Check that the appropriate files are staged: git status
  6. Commit the changes: git commit
  7. (Optional) If, at this stage, your branch not up-to-date with the latest main, rebase using git rebase origin/main OR merge using git merge origin/main
  8. Push to remote branch with same name: git push -u origin 42-new-branch
  9. Create a Pull Request with, for example, Closes #42 in the body to link the issue
  10. Merge the branch on GitHub and delete the branch after
  11. Assuming you are still on your branch, update your local repo with git pull origin main:main
  12. Switch to main: git checkout main
  13. Delete your branch: git branch -d 42-new-branch

Updating your branch while it is still in progress

Sometimes while you are working on a branch, someone uploads some code that fixes something and you want those fixes locally. To update your local repository use the following:

  1. Commit or stash your changes: git commit OR git stash
  2. Switch to main: git checkout main
  3. Update main: git pull
  4. Return to your branch: git checkout 42-my-branch
  5. Rebase or merge: git rebase main OR git merge main
  6. (Optional) If you stashed your changes, reapply them: git stash apply

Note that for steps 5 and 6 you might have to resolve some conflicts. Usually you want to keep your own changes since they are the latest changes. If you are confused, please discuss with your team on which changes to keep.

Happy hacking!

--

--