GIT Workflow for Teams
I suggest the following workflow for your team projects to minimize merge conflicts. It is based on using one branch per person in the team and using Gitlab's Merge Request to share each person's changes with the team.
Clone the Project Repository
For team projects, you will want to clone the team repository directly (instead of forking your own copy) so that everyone is working on the same code base.
- Each person in the team should simply clone the team repository:
git clone git@coursework.cs.duke.edu:CompSci308_2018Fall/cellsociety_teamNN.git
- Then create a New Project in IntelliJ from that existing source so it uses the same folder you just created when you cloned the team repository to your local machine
One Branch per Person
The advantage of using one branch per person (instead of each package or feature) is that it essentially assures that you are the only one using your branch, meaning you will only need to push your changes periodically so they are available in Gitlab and can be integrated into the master branch and you will not need to pull any new changes.
- Each person in the team should create a branch for themselves to work on exclusively throughout the project:
git checkout -b YOUR_NAME_OR_NETID
- Then you would work in this branch as usual during the project:
git add YOUR_UPDATED_FILES git commit -m "A useful comment for your team mates about this change" git push -u origin BRANCH_NAME
Integrate Your Changes with the Team
Merge Requests are a powerful tool provided by many online GIT repositories (including GitHub and BitBucket). It creates a web page representing the changes you intend to make to the repository in an easy to understand format that allows others to comment on your changes before accepting them. The request's web page also updates automatically if new changes are committed and pushed.
- Rather than working directly with the
masterbranch on your local machine, use Gitlab's Merge Request tool to manage integration - When you are ready to integrate your changes with the team's stable version of the project, go to the team's project repository web page
- Select "Merge Request" from the top of the project and select "New Merge Request" on the resulting page
- Select your branch as the "Source Branch" and
masteras "Target Branch" (masteris the default), then select "Compare branches and continue" - If there are no conflicts, then simply wait for others on your team to approve the Merge Request
- If there are conflicts, your team will need to resolve them. You can either do that directly on the web page or by changing your code locally then committing and pushing it again.
Note, if you do resolve the conflicts using the online interface you will need topullthose changes down to your branch's local copy before doing the next steps.
Integrate the Team's Changes with Your Code
This step is most likely to contain merge conflicts since you have been coding on your branch without worrying about what the rest of the team has been doing (so the longer you wait to push your code the more likely it is that you will cause conflicts).
- After a Merge Request has been accepted by the team, there will be new code on the
masterbranch - To merge this new code with your personal branch, you have two options:
- Create a Merge Request on Gitlab (as above) from the
masterbranch to your personal branch ormergeit directly using the command line. This has all the advantages as above, including being able to use the web interface to resolve conflicts, and will require you topullthe changes down to your local repository after finishing. Also, using the web interface means you will never need to leave your branch on your local machine. - Use the command line. This can be more stream lined, especially if there are no conflicts.
- Each person in the team would need to change into the
masterbranch on their local machine to pull down these new changes
git checkout master git pull origin master - This merge should proceed smoothly since you have not made any local changes to the
masterbranch - Change back into your personal branch and merge the new changes from the
masterbranch
git checkout -b YOUR_NAME_OR_NETID git merge master - This is where you may get conflicts. If so, fix them (perhaps by consulting with your team mates) and create a
commitjust for the fixes andpushit up to Gitlab as usual.git add YOUR_UPDATED_FILES git commit -m "A useful comment for your team mates about this change" git push -u origin BRANCH_NAME
- Create a Merge Request on Gitlab (as above) from the
- Take a moment to admire the new updates to your project, then get back to work on your part of the project :)