CompSci 308 Spring 2024 |
Advanced Software Design and Implementation |
You can do a lot of things with GIT, and many of the rules of what you should do are not so much technical limitations but are about what works well when working together with other people. — Linus Torvalds, inventor of Linux and GIT
The following workflow is suggested 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 (Merge Requests can also be an valuable tool to help team mates review and communicate about each other's code).
For team projects, each person should clone
the team repository directly so that everyone is working on the same code base (there should be no reason to fork
your own copy).
clone
the shared team repository:git clone git@coursework.cs.duke.edu:CompSci308_2024spring/PROJECT_teamNN.git
New -> Open
and select the folder you just created when you cloned the team repository to your local machineThe advantage of using one branch per person (instead per feature or package) is that it essentially assures that you are the only one using your branch, meaning you will only need to push
your changes regularly so they are available in Gitlab and can be integrated into the main
branch and you will not need to pull
any new changes.
git checkout -b YOUR_NAME_OR_NETID
git add YOUR_UPDATED_FILES git commit -m "A useful comment for your team mates about this change" git push -u origin BRANCH_NAME
In this way, each team member has a personal branch (a place to experiment or have Work In Progress, WIP) to work in and main
becomes the team branch (a representation of the latest stable version of the entire project).
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 to reflect new changes that are commit
ted and push
ed until it is closed.
main
branch, go to the team's project repository web pageMerge Requests → New Merge Request
from the project website's left sidebar and then on the resulting pageSource Branch
and main
as Target Branch
(main
is the default), then select Compare branches and continue
pull
those changes down to your branch's local copy before doing the next steps.In summary, push
your personal branch changes to Gitlab and create a Merge Request to the main
, team, branch.
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).
main
branchmain
branch to your personal branchpull
the changes down to your local repository after finishing.
git checkout -b YOUR_NAME_OR_NETID git pullAlso, using the web interface means you will never need to "leave" your branch on your local machine.
merge
directly. This can be more stream lined, especially if there are no conflictsmain
branch on your local machine to pull
down the new changesgit checkout main git pull origin main
merge
should proceed smoothly since you have not made any local changes to the main
branchmain
branchgit checkout BRANCH_NAME git merge main
commit
just for the fixes and push
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
In summary, merge
the main, team, branch changes with your personal branch (either remotely via Merge Request or locally via the Terminal) and pull
them to your computer.