Lab 10: git & GitHub | CMSC 240 Software Systems Development - Fall 2024

Lab 10: git & GitHub

Instructions

Group 1

Overview

In this lab, you will work in groups of three (there may be one or two group of four), experimenting in the use of git (for your local version of a repository) and GitHub (where, via git, the three of you will combine your work). You will ultimately implement a working solution to a collection of C++ classes/programs that includes:

Each class depends on the other two classes, and VectorTester.cpp will eventually test all three classes.

The team of four will also have ShortVector.h and ShortVector.cpp, so that each class will depend on three other classes, and VectorTester.cpp will eventually test all four classes.

Your assigned class will be CharacterVector, DoubleVector, or IntegerVector based on the alphabetical order of your first name. For example, if your name is first in alphabetical order than you edit CharacterVector, the next takes DoubleVector, and the last takes IntegerVector. If you have a group of four then the fourth person will get ShortVector.

Setup

GitGraph

GitGraphLaunch

$ git config --global pull.rebase false

Steps

Show which branch you’re on – the main branch

$ git branch

Create a new feature branch.

$ git branch YOUR_NAME_feature_branch

Show that you are still on the main branch.

$ git branch

Change to your new branch.

$ git checkout BRANCH_NAME  

Show you’re on your new branch.

$ git branch 

Check status of your changes.

$ git status

Stage the files that you modified.

$ git add *.cpp      

Check that your changes have been staged.

$ git status

Commit your work to your local feature branch.

$ git commit -m "Your detailed commit message here"

Check that your changes have been committed.

git status 

In case others made changes to the remote main branch, update your local main branch from the remote main branch.

git pull origin main

Show which branch you’re on.

git branch

Switch to the main

git checkout main

Show which branch you’re on now.

git branch

Show main’s (older) version of the .cpp file.

cat YOUR_CLASS.cpp

Merge your branch into the (current) main branch.

git merge YOUR_NAME_feature_branch  

View the main branch version of your .cpp file after your feature branch was merged into the main branch.

cat YOUR_CLASS.cpp

Should show you ahead of origin/main.

$ git status

Push to the remote repository

git push origin main

Execute this command to output details about the remote repository.

git remote show origin
$ git checkout YOUR_NAME_feature_branch
$ git branch

# Do work in VectorTester.cpp

$ git status
$ git pull origin main
$ git add *.cpp
$ git status
$ git commit -m "Your detailed commit message here"
$ git status
$ git checkout main
$ git branch
$ git merge YOUR_NAME_feature_branch
$ git status
$ git push origin main
$ git remote show origin

Using Git in VSCode

Handling Pull Conflicts

When doing a fetch-and-merge from the remote repository (via git pull origin main), git will do its best to merge your local repository’s code with (potentially different) code that exists on the remote repository. In many cases — particularly if you make a practice of regularly keeping your local repo up-to-date via regular pulls — git can itself handle merging using the “recursive strategy”. In such cases, you should see a message similar to the following:

Merge made by the 'recursive' strategy.

In some cases, however, git’s recursive strategy will not work, and conflicts will result that you must handle explicitly. (One such situation is a conflict of a teammate’s “good” code in their assigned class versus your “stub” code in their assigned class.)

If you get an error start by typing the following:

$ git config pull.rebase false

Then attempt to pull again.

$ git pull origin main

When git cannot automatically merge, you will see a message similar to the following:

$ git pull origin main
From https://github.com/cmsc240-f23/lab10
    * branch            main     -> FETCH_HEAD
Auto-merging VectorTester.cpp
Auto-merging IntegerVector.cpp
CONFLICT (content):  Merge conflict in IntegerVector.cpp
Auto-merging DoubleVector.cpp
CONFLICT (content):  Merge conflict in DoubleVector.cpp
Auto-merging CharacterVector.cpp
CONFLICT (content):  Merge conflict in CharacterVector.cpp
Automatic merge failed; fix conflicts and then commit the result.

You will then need to edit each file for which there is a conflict:

$ git add *.cpp
$ git commit  # (will offer a merge comment in vim – just :wq to accept) 
$ git branch
$ git checkout main
$ git branch
$ git merge YOUR_NAME_feature_branch 
$ git push origin main 
$ git remote show origin