12. Look at git log. Notice that there is a merge commit. Also look in gitk. Notice the DAG
now shows how things forked, and then were joined up again by a merge commit.
Stretch Task
1. Once again, checkout your branch. Make a couple of commits.
2. Return to your master branch. Make a commit there that changes the exact same line, or
lines, as commits in your branch did.
3. Now try to merge your branch. You should get a conflict.
4. Open the file(s) that is in conflict. Search for the conflict marker. Edit the file to remove the
conflict markers and resolve the conflict.
5. Now try to commit. Notice that Git will not allow you to do this when you still have
potentially unresolved conflicts. Look at the output of status too.
6. Use the add command to add the files that you have resolved conflicts in to the staging
area. Then use commit to commit the merge commit.
7. Take a look at git log and gitk, and make sure things are as you expected.
8. If time allows, you may wish to...
Delete everything but your .git directory, then do a checkout command, to prove
to yourself that this really will restore all of you current working copy.
Create a situation where one branch has changed a file, but the other branch has
deleted it. What happens when you try to merge? How will you resolve it?
Look at the help page for merge, and find out how you specify a custom message for
the merge commit if it is automatically generated.
Look at the help page for merge, and find out how to prevent Git from automatically
committing the merge commit it generates, but instead give you chance to inspect it
and merge it yourself.
Exercise 3
For this task, you will work in a small group. Between 2 and 4 people is about right.
Main Task
1. First, one person in the group should create a public repository using their GitHub account.
2. This same person should then follow the instructions from GitHub to add a remote, and
then push their repository. Do not forget the –u flag, as suggested by GitHub!
3. All of the other members of the group should then be added as collaborators, so they can
commit to the repository also.
4. Next, everyone else in the group should clone the repository from GitHub. Verify that the
context of the repository is what is expected.
5. One of the group members who just cloned should now make a local commit, then push it.
Everyone should verify that when they pull, that commit is added to their local repository
(use git log to check for it).
6. Look at each other’s git log output. Notice how the SHA-1 is the same for a given commit
across every copy of the repository. Why is this important?
7. Two members of the group should now make a commit locally, and race to push it. To keep
things simple, be sure to edit different files. What happens to the runner-up?