Git branching basic workflow

To better handle multiple people working on a project in a Git repository, using branches and reviewing pull requests before committing to the master branch is strongly suggested.

Basic steps:

  1. Change to your home directory and clone the git repository
  2. cd $HOME
  3. git clone [email protected]/MyRepo.git
  4. Change into the new project directory
  5. cd ./MyRepo
  6. Create a branch to work on the new code
  7. git checkout -b MyNewBranch
  8. Verify you are working in the branch
  9. git branch
  10. Note: The branch will have a “*” to the left of the branch name denoting the active branch
  11. Update code, test, repeat
  12. Review and add any missing files
  13. git status
  14. git add
  15. Push the code into the repository
  16. git push –set-upstream origin MyNewBranch
    1. This is only necessary for the first ‘git push’
  17. git commit -v {list of changed files}
    • Note the response from the system:
    • remote: Create a pull request for 'MyNewBranch' on GitHub by visiting:
    • remote: https://git.repo.example.org/MyRepo/pull/new/MyNewBranch
  18. Open the pull request (PR) in git.repo.example.org
  19. Add other repository contributors to request a code review before merging.
  20. Repeat the edit/test/PR cycle as necessary until merge is accepted
  21. edit code … test … git status … git add … git commit … git push
  22. When it has been accepted, clean-up your work area:
    1. cd $HOME/MyRepo/
    2. git checkout master
    3. git pull
    4. git branch –delete MyNewBranch
  23. Celebrate on a successful pull request!