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:
- Change to your home directory and clone the git repository
- cd $HOME
- git clone [email protected]/MyRepo.git
- Change into the new project directory
- cd ./MyRepo
- Create a branch to work on the new code
- git checkout -b MyNewBranch
- Verify you are working in the branch
- git branch
- Note: The branch will have a “*” to the left of the branch name denoting the active branch
- Update code, test, repeat
- Review and add any missing files
- git status
- git add <file_name>
- Push the code into the repository
- git push –set-upstream origin MyNewBranch
- This is only necessary for the first ‘git push’
- 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
- git push –set-upstream origin MyNewBranch
- Open the pull request (PR) in git.repo.example.org
- Add other repository contributors to request a code review before merging.
- Repeat the edit/test/PR cycle as necessary until merge is accepted
- edit code … test … git status … git add … git commit … git push
- When it has been accepted, clean-up your work area:
- cd $HOME/MyRepo/
- git checkout master
- git pull
- git branch –delete MyNewBranch
- Celebrate on a successful pull request!