Introduction to using Git in a Team

This lab has been modified to use SSH rather than personal access tokens. Make sure you have completed the the steps for Using Git with SSH.

In this lab, you will you will work through the process of constructing a repository for working in a pair and for making and sharing changes using your pair repository.

You will be allowed to work in pairs for some assignments. In this lab, you are going to work through the most basic way to use a repository to work collaboratively with another person. You will learn more complex ways to use Git in a team as the year goes on.

You will need to identify a partner to work with for this part. Please ask someone sitting next to you to be your partner for this assignment. You’ll be able to choose more thoughtfully once we get to team assignments.

As in the previous labs, you will need to be logged into the CS Linux servers to do this lab.

To create the name for your team, combine your CNetIDs, in alphabetical order, separated by a dash. For example, if one of you has the CNetID ar0r and the other has the CNetID borja, then the name of your team is ar0r-borja.

In the text below, Person A is the person whose CNetID comes first in alphabetical order and Person B is the person whose CNetID comes second. In our example above, ar0r would play the role of Person A and borja would play the role of Person B.

Step 1: Create and join a Team

To work in a pair, the partners need to create the team and accept the assignment (and the team). The partners have different roles to play in this process and different commands to run as a result.

We supplied a URL that you will need as you work through this lab in the Ed posting, Please open a browser and log into Ed to have access to the link.

Person A Please follow these steps. Open a browser and go to the TEAMS URL shared on Ed. The identifier for this team will not be in the list of possible teams, so please follow the instructions to create the team A-B (where A is your CNetID and B is Person B’s CNetID). Once the team is created, go ahead and accept the assignment.

Person B Please follow these steps after Person A accepts the assignment. Open a browser and go to the TEAMS URL. Your team’s name (A-B) should now be on the list of possible teams. Select your team (A-B) from the list and accept the assignment.

Once this process is finished, GitHub will create an empty repository for the team to use for the assignment. It may take a couple of minutes for your repository to be created. Please verify that the team repository exists before moving on to the next part.

Step 2: Initial repository setup

As with individual assignments, you will need to initialize your repository and make a local copy. As in the previous step, the partners will have different roles to play.

To simplify the task, each partner should set up an environment variable by running the following command at the Linux command-line:

TEAM=A-B

where A should be replace with Person A’s CNetID and B should be replaced with Person B’s CNetID. Verify that the team name is correct by running:

echo $TEAM

If the result is A-B (literally), please redo the previous command with the appropriate values for A and B.

Person A Here are the steps you need to complete. To get started, navigate to your capp30121 directory, create a subdirectory named camp-4-$TEAM, and then change to that new camp-4-$TEAM directory.

cd ~/capp30121
mkdir camp-4-$TEAM
cd camp-4-$TEAM

Before moving on, use pwd to make sure you are in the right place (/home/USER/capp30121/camp-4-A-B).

Next you will initialize the repository by running the commands listed below in your camp-4-A-B directory. We encourage you to run the commands one-by-one and to verify that each command ran without generating an error message before moving to the next command:

git init
git remote add origin git@github.com:uchicago-CAPP30121-aut-2021/camp-4-$TEAM.git
git remote add upstream git@github.com:uchicago-CAPP30121-aut-2021/camp-4-initial-code.git
git pull upstream main
git branch -M main
git push -u origin main

If you run an ls, you should see that your directory now contains one file:

README.md

Person B Here are the steps that you need to complete. You do not need to initialize the repository. You just need to clone it (i.e. make a local copy) and connect the upstream repository to that local copy. You should run the commands below in your capp30121 directory. Make sure to replace A with Person A’s CnetID and B with your CNetID:

cd ~/capp30121
git clone https://github.com/uchicago-CAPP30121-aut-2021/camp-4-$TEAM.git
cd camp-4-$TEAM
git remote add upstream https://github.com/uchicago-CAPP30121-aut-2021/camp-4-initial-code.git

The first command makes sure you are in the right directory. The second command will make a local copy of the repository. The third command moves you into the directory for the new repository. And the last command connects the local copy to the upstream repository.

Step 3: Merge conflict

Let’s cause a merge conflict! Recall that merge conflicts happen when different copies of the repository diverge from each other.

First both partners should edit their local copy of README.md by replacing Add your name(s) here their name. Unless the two partners have the same name, the copies will get out of sync.

Person A should add, commit, and push their changes to README.md to the server.

When Person A is done, Person B should add and commit their changes. Person B can try to do a push but it will fail, since Person B’s copy of the repository is out of sync with the server. So, what should Person B do? A pull (git pull)! The pull will signal a merge conflict and update README.md to indicate the source of the conflict.

Both Person A and Person B should have a look at the conflicts using an editor on Person B’s machine and find a way to reconcile them (e.g. include both names and remove the conflict markers (=== and >>>)). Person B should then add, commit, and push the changes to the server.

Person A should do a pull (on their own copy) to get back in sync with Person B and with the server.

How do you avoid merge conflicts when working with someone else? For now, the best way is to work together on one copy of the repository. (That’s also the best way to learn from each other.) If you choose to work separately, both partners must be very disciplined: always pull before you start working on the code, add/commit/push your changes when you are done, and make sure that only one person is actively working on the same code at one time.

Useful Resource

Working with a partner can be a great experience, and one that more closely resembles the way in which software is developed in real projects, but working with another person can also be challenging. We encourage you take a look at the Working in Teams page of the CS Developer Guide, but please note that you should skip the “Using Git Effectively” section, as that section covers advanced techniques that are not relevant in this class. You’ll learn about some of these techniques later in the year.