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_2018Spring/cellsociety_teamNN.git
- Then create a Java Project within Eclipse that is set to the same folder you just created when you cloned the team repository to your local machine
One Branch per Person
The advantage of using this approach is that, assuming you are the only one using your branch, you will only need to push
your changes periodically so they are available in Gitlab and can be integrated into the master
branch and 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 also updates automatically if new changes are pushed to the repository.
- Rather than working directly with the
master
branch 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 navigation tabs at the top of the project and select "New Merge Request" on the resulting page
- Select your branch as the "Source Branch" and
master
as "Target Branch" (master
is 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 topull
those 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.
- After a Merge Request has been accepted by the team, there will be new code on the
master
branch - To merge this new code with your personal branch, you have two options:
- Create a Merge Request on Gitlab (as above) from the
master
branch to your personal branch ormerge
it 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 topull
the 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 should change into the
master
branch 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
master
branch - Change back into your personal branch and merge the new changes from the
master
branch
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
commit
just for the fixes andpush
it 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 :)