Version CTRL Git
Version CTRL Git
a. update
b. checkout
c. clone
d. import
5. True or False? In Git, if you want to make your local repository reflect changes that have been made
in a remote (tracked) repository, you should run the pull command.
a. True
b. False
6. In Git, which error would you get if you try to push master-branch changes to a remote repository,
and someone else pushed changes to that same branch while you were making your changes? (Choose
one.)
a. Rejected
b. 404
c. 500
d. Access denied
7. If you want to make radical changes to your team’s project and don’t want to impact the rest of the
team, you should implement your changes in …
a. … a tag.
b. … the trunk.
c. … the root.
d. … a branch.
a. checkout
b. clone
c. export
d. revert
e. update
9. Now, imagine that you have a local repository, but other team members have pushed changes into the
remote repository. What Git operation would you use to download those changes into your working
copy?
a. checkout
b. commit
c. export
d. pull
e. update
d. a and b
e. a, b, and c
11. Which Git command changes where the HEAD pointer points and modifies the contents of the work-
ing directory?
a. checkout
b. merge
c. mv
d. pull
12. Which one of the following is not part of the data structure of a Git repository?
a. Body element
b. Branch pointer
c. Commit object
d. HEAD pointer
1. b
2. d
3. d
4. c
5. a
6. a
7. d
8. b
9. d
10. d
11. a
12. a
Problem:
Consider the following scenario involving Git. Alice and Bob are both working on a shared project My-
Proj that is stored in a remote Git repository. Bob does a clone on the remote repository. What two things
does Git create when Bob issues the clone command?
Next, Bob edits the MyProj file foo.rb. Then, he does a commit and a push. What does Git do when Bob
issues these commands?
Next, Alice does a clone on MyProj. Then, Alice and Bob both edit foo.rb in parallel. foo.rb has over
100 lines of code. Alice edits a couple lines at the top of the file, and Bob edits a couple lines at the bot-
tom of the file. Then, Bob does a commit and a push. Finally, Alice does a commit and a push. What
does Git do when Alice issues the push command?
What Git commands should Alice issue next and what would the result of the command be?
Solution:
Consider the following scenario involving Git. Alice and Bob are both working on a shared project My-
Proj that is stored in a remote Git repository. Bob does a clone on the remote repository. What two things
does Git create when Bob issues the clone command?
When Bob issues the checkout command, Git creates a local copy of the MyProj repository and a
working directory that contains the latest snapshot of the project files.
Next, Bob edits the MyProj file foo.rb. Then, he does an add, a commit and a push. What does Git do
when Bob issues these commands?
The add commands “stages” the changes. The commit command updates Bob’s local repository to
reflect the changes. The push command updates the remote repository to reflect the changes in Bob’s
local repository.
Next, Alice does a clone on MyProj. Then, Alice and Bob both edit foo.rb in parallel. foo.rb has over
100 lines of code. Alice edits a couple lines at the top of the file, and Bob edits a couple lines at the bot-
tom of the file. Then, Bob does an add/commit/push. Finally, Alice does a add/commit/push. What
does Git do when Alice issues the push command?
When Alice issues the push command, Git rejects her push because the remote branch has changed
since the last time she pulled from it.
What Git commands should Alice issue next and what would the result of the command be?
Alice should do a pull on the remote repository. That will update her current branch in her local repos-
itory as well as her working directory. The update will both download the changes in the remote repos-
itory and merge them into her current branch. To then upload the merged changes, she would need to
do an add/commit/push.
Problems:
Draw the state of the pictured repository after a Git commit operation (make up a hash).
Before: After:
HEAD%
master%
98ca9% 34ac2%
myfix%
Draw the state of the pictured repository after running the following commands.
$ git checkout master
$ git merge myfix
Before: After:
master%
98ca9% 34ac2%
myfix%
HEAD%
Solutions:
Draw the state of the pictured repository after a Git commit operation (make up a hash).
Before: After:
HEAD%
master%
98ca9% 34ac2%
myfix%
Draw the state of the pictured repository after running the following commands.
$ git checkout master
$ git merge myfix
Before: After:
master%
98ca9% 34ac2%
myfix%
HEAD%
Problems:
1. Imagine a Git repository (“repo”) with one commit and one branch (master). A user makes a new
commit to the repo. Draw a box-and-line diagram of the repo like the diagrams shown in class. In-
clude all commit nodes (with made-up hashes), all HEAD nodes, and all branch nodes.
2. Continuing the previous scenario, the user creates and checks out a new branch “my-branch” and then
makes a new commit. Update the previous diagram to reflect these actions.
Solutions:
1.
2.
Multiple-Choice Questions:
Version A Version B
Version C Version D
Now, imagine the following scenario. Alice and Bob are using GitHub to collaborate on a Rails project.
They both are working in parallel on Version A of cat.rb. Each modifies the file cat.rb as follows: Alice
changes it to be Version B, whereas Bob changes it to be Version C (note the difference in length maxi-
mum).
Bob commits his changes first, and pushes them to the GitHub repo. Then, Alice commits her changes.
1. Which one of the following would happen if Alice next did a Git push?
a. Her commit would be added to the GitHub repo, making the current version in GitHub be
Version B
b. Her commit would be merged with Bob’s in the GitHub repo, making the current version in
GitHub be Version D
c. Her push would be rejected, leaving the current version in GitHub as Version C
d. Her push would be rejected, leaving GitHub unchanged, and Bob’s code would be download-
ed and merged into her working directory, making her working copy Version D
2. Which one of the following would happen if Alice instead did a Git pull?
a. Her pull would be rejected, leaving her working directory with Version B of cat.rb
c. This example is invalid: The node to which “experiment” directly points (C3) should not be
reachable from the node to which “master” directly points (C5)
1. c
2. c
3. a
Problem:
What type of system is Git? Describe three software engineering problems Git helps you solve.
Solution:
Problems:
Alice is working on a collaborative software project with a team of seven other developers. The project is
an airline-booking web app called FlyMe. The code for the project is housed in a GitHub repo. All work
for the project is being done on the “master” branch (no other branches). Alice has been helping on the
project for a while, and has a local copy of the repo and a working directory on her computer.
1. Alice has just edited the web-app code on the master branch to add a feature that enables users to re-
quest window or aisle seats when they book flights. She wants to save these changes in her local repo.
Which command(s) from the above list should she run next?
2. Having saved the changes in her local repo, Alice now wants to share them with the rest of the team
by uploading them to the GitHub repo. Which command(s) from the above list should she run next?
When she runs the command(s), she gets this message (with words that give away the answers hidden):
To https://github.com/.../flyme.git
! [rejected] master -> master (fetch first)
error: failed to push some refs to 'https://github.com/.../flyme.git'
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first integrate the remote changes
hint: (e.g., 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
3. Alice wants to resolve this issue, so she can upload her changes. Which (one) command from the
above list should she run next?
Solutions:
1. c, e
2. b
3. j
Problems:
Draw the state of the pictured repository after a Git commit operation (make up a hash).
Before: After:
master%
98ca9% 34ac2%
myfix%
HEAD%
Draw the state of the pictured repository after running the following command.
Before: After:
HEAD%
master%
98ca9% 34ac2%
myfix%
Solutions:
Draw the state of the pictured repository after a Git commit operation (make up a hash).
Draw the state of the pictured repository after running the following command.
Giada has just joined a team of developers collaboratively working on a restaurant management web app
called DineOh. The code for the project is housed in a GitHub repo. All work for the project is being done
on the “master” branch (no other branches).
1. Giada wants to get a local copy of the code and repo, so she can begin contributing to the project.
Which command(s) from the above list should she run?
2. Giada does some work on the project, but then, she is suddenly called upon to fix a critical bug in an-
other project. She is distracted by this debugging task for a couple days. When she finally returns to
the DineOh project, she cannot remember if she saved her edits to the local repo. Which command(s)
from the above list should she run to determine whether or not she saved her edits?
3. The command tells her that she had only edited the files, but not run any other Git commands since
doing so. Which command(s) from the above list should she run to save her edits to the local repo?
4. Having saved to her local repo, she would now like to share her work with the rest of the team (via
GitHub). Which command(s) from the above list should she run?
When she runs the command(s), she gets this message (with words that give away the answers hidden):
To https://github.com/.../dineoh.git
! [rejected] master -> master (fetch first)
error: failed to push some refs to 'https://github.com/.../dineoh.git'
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first integrate the remote changes
hint: (e.g., 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
5. Giada wants to resolve this issue, so she can upload her changes. Which (one) command from the
above list should she run next?
Solutions:
1. g
2. i
3. c, e
4. b
5. j
Problems:
1. Draw the state of the pictured repository after a Git commit operation (make up a hash).
Before:
98ca9 34ac2
master
HEAD
After:
2. Draw the state of the local repository after a Git pull operation.
master master
HEAD
1.
2.
Problems:
Bonita has just joined a team of developers collaboratively working on a real estate sales web app called
ProperProperty. The code for the project is housed in a GitHub repo. All work for the project is being
done on the “master” branch (no other branches).
1. Bonita wants to get a local copy of the code and repo, so she can begin contributing to the project.
Which command(s) from the above list should she run?
2. She makes some changes to the code. Which command(s) from the above list should she run to save
her edits to the local repo?
3. Having saved to her local repo, she would now like to share her work with the rest of the team (via
GitHub). Which command(s) from the above list should she run?
When she runs the command(s), she gets this message (with words that give away the answers hidden):
To https://github.com/.../dineoh.git
! [rejected] master -> master (fetch first)
error: failed to push some refs to 'https://github.com/.../dineoh.git'
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first integrate the remote changes
hint: (e.g., 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
4. Bonita wants to resolve this issue, so she can upload her changes. Which (one) command from the
above list should she run next?
5. The command completes with no conflicts. What command(s) should Bonita run to at last share her
work with the rest of the team?
Solutions:
1. g
2. c, e
3. b
4. j
1. Draw the state of the pictured repository after a Git commit operation (call your hash cdcdcd).
Before:
ababab bcbcbc
master
After:
2. Draw the state of the local repository after a Git pull operation.
master master
1.
2.