An exercise for collaborating with git / GitHub. Please read the directions CAREFULLY! I recommend focusing on the changes to the README before reading the Java code.
- Each partner should run these commands on their own terminal. DO NOT SKIP THIS PART!!!
This will tell git to perform fast forwards when possible, never rebase, and create merge commits when necessary. We will not cover the differences between these in-depth in class, but feel free on your own time to research them using search engines or AI if you're interested. Explore your curiosity!
git config --global pull.ff true git config --global pull.rebase false
- Choose one partner to be Partner A, one partner to Partner B.
- Have ONLY Partner A fork this repository. PARTNER B SHOULD NOT FORK.
- Have Partner A add Partner B as a collaborator on their fork. Follow these directions.
- Have the Partner A send the URL of their repository to Partner B.
- Partner B should see an invitation at the top of the repository. Click "View Invitation", then "Accept Invitation".
- Both partners should clone the repository to their own computer. The URL should include Partner A's username.
- Both partners should change into the project repository:
cd grcsay
- Both partners should open VSCode in the project repository. If the below command does not work, open VS Code and use File > Open Folder.
code .
We will first practice making changes that do not trigger a merge conflict. In general, this is what we hope to happen!
- Partner A will make changes first. ONLY PARTNER A SHOULD DO THESE SUB STEPS to add, commit, and push the changes.
- Do a git pull. You should get a message saying you're up to date.
git pull
- Make any change to the README and save it.
- Check that the change shows up in red (shows as unstaged) when asking for the status.
git status
- Add (stage) the change.
git add README.md
- Check that the change shows up as green (staged for commit).
git status
- Commit the change. Change the commit message to describe your commit.
git commit -m "DESCRIBE YOUR CHANGE HERE"
- Push the changes to GitHub
git push origin
- Do a git pull. You should get a message saying you're up to date.
- Go to Partner A's fork on GitHub. Refresh the page and verify the changes show up.
- Have Partner B pull Partner A's change. ONLY PARTNER B SHOULD DO THIS:
git pull
- Verify that the changes are downloaded locally to Partner B's computer. At this point, the code on both computers should be exactly the same.
- Have ONLY Partner B now make a change to the README. Partner B should add, commit, and push the change following the above steps.
- Have Partner A pull partner B's changes. Verify that the changes are downloaded locally to Partner B's computer. At this point, the code on both computers should be exactly the same again.
We will now artificially trigger a merge conflict. When we follow good git practices (small, frequent commits, pulling frequently) these won't happen as often. But they will happen time to time! In this part we'll get experience in resolving them once they arise.
- Have BOTH Partner A and Partner B edit the below line. Each person should make it say something different.
EDIT THIS LINE
- Have BOTH Partner A and Partner B add, commit, and push the changes. You can refer to the above steps for a refresher on how to add/commit/push. One of the partners will get an error saying that their changes can't be pushed. This is OK and expected. Today we are practicing how to resolve this error.
- Have the error partner pull the other partner's changes:
git pull
- There will be an message about a merge conflict. This is expected! This is what we're practicing how to resolve.
- Have the partner who got the error run git status. It should tell you that there is a merge conflict and you both have modified
README.md
git status
- ONLY the error partner should open the README in VSCode. There should be both changes and extra text separating them. It will look something like this:
- Resolve the merge conflict to include both of the changes and delete the extra lines.
- Mark the conflicted file as resolved with git add.
git add README.md
- Run git status again. The README should be in green.
git status
- Commit the confict resolution:
git commit -m "Resolved merge conflict"
- Push the changes to GitHub.
git push
- Have the other partner pull the changes and verify that both changes are there:
git pull
- The code should be the same on both computers. Congrats on resolving your first merge conflict!
- Both partners should compile the project. Make sure that you are in the root of the project's directory.
javac src/*.java
- Both partners should try running the project:
java -cp src SayApp
- Follow the prompts to give input and run the program.
- Make sure it works on both computers.
- Read through the code and understand what it's doing. Talk with your partner about it! Talk about any object-oriented practices you see occuring. Talk about what data structures are used.
- Each partner should make a new class that implements the Animal interface. Each person should do this on their own computer! There is some ASCII art provided below, but feel free to add your own if you prefer. If you copy from some source on the internet please make sure to add attribution in a comment. Note that you may need to escape some characters if you make your own art.
- Always make sure to save and compile your files again before re-running the program. As you're working, follow good git practices of pulling, editing, adding, committing, and pushing.
- Add your animal to the
animalList
method inSayApp.java
- Make sure to push and pull each other's changes.
- Merge conflicts may arise! This is OK! Keep calm and resolve them as they come up.
- Have ONLY PARTNER A make a pull request against the original repository.
- Have partner A give the URL of the pull request to partner B.
- BOTH PARTNERS MUST SUBMIT THE URL OF THE PULL REQUEST TO CANVAS. You will both be submitting the same URL.
Try updating the program so that it can handle multiple lines of text. Or make any other change you find interesting!