Learn Enough to Be Dangerous
You have to make a choice. Choose...wisely.

Get occasional notifications about things like product discounts, blog posts, and new or updated tutorials. Unsubscribe at any time.

Gift Delivery Options
Quick Checkout
or Pay by Credit Card
Error processing your payment
  • You didn't choose whether or not to be added to the mailing list
Confirm
$0.00

Payments and credit card details are securely managed and protected by Learn Enough's payment processor, Stripe. More information on their site:

CART
Total
$0.00

Your Cart is Empty

$30
$300
$300
$XY
$XY
1234
  • Git

Learn Enough Society

Certificate of Course Completion

This page certifies that kartikmandar has completed Learn Enough Git to Be Dangerous! 🎉

About the tutorial
Learn Enough Git to Be Dangerous by Michael Hartl covers an often-overlooked but essential skill in modern computing: version control. Git, the most popular and powerful version-control system, lets you track changes in software projects while also enabling collaboration with millions of developers around the world. Read full post
23 Nov 02:38, 2022
13 May 06:46, 2023
Exercise Answers
Exercise Question:
  • Run git help at the command line. What is the first command listed?
  • kartikmandar's Answer:
    Exercise Question:
  • There’s a chance that the full output of git help was too big to fit in your terminal, with most of it just scrolling by. What’s the command to let us navigate the output of git help interactively? (On some systems, you can use the mouse to scroll back in the terminal window, but it’s unwise to rely on this fact.) Hint: Pipe the output to less.
  • kartikmandar's Answer:
    Exercise Question:
  • Git stores global configuration settings in a hidden text file located in your home directory. By inspecting the file ~/.gitconfig with a tool of your choice (cat, less, a text editor, etc.), confirm that the configuration set up by Listing 1.3 corresponds to simple text entries in this file.
  • kartikmandar's Answer:
    Exercise Question:
  • By running ls -a (discussed in Learn Enough Command Line to Be Dangerous), list all the files and directories in your website directory. What is the name of the hidden directory used by the Git repository? (There is one such hidden directory per project.)
  • kartikmandar's Answer:
    Exercise Question:
  • Using the result of the previous exercise, run ls on the hidden directory and guess the name of the main Git configuration file. Use cat to dump its contents to the screen.
  • kartikmandar's Answer:
    Exercise Question:
  • Using the touch command, create empty files called foo and bar in your repository directory.
  • kartikmandar's Answer:
    Exercise Question:
  • By using git add foo, add foo to the staging area. Confirm with git status that it worked.
  • kartikmandar's Answer:
    Exercise Question:
  • Using git commit -m and an appropriate message, add foo to the repository.
  • kartikmandar's Answer:
    Exercise Question:
  • By using git add bar, add bar to the staging area. Confirm with git status that it worked.
  • kartikmandar's Answer:
    Exercise Question:
  • Now run git commit without the -m option. Use your Vim knowledge to add the message “Add bar”, save, and quit.
  • kartikmandar's Answer:
    Exercise Question:
  • Using git log, confirm that the commits made in the previous exercises worked correctly.
  • kartikmandar's Answer:
    Exercise Question:
  • Use touch to create an empty file called baz. What happens if you run git commit -am "Add baz"?
  • kartikmandar's Answer:
    Exercise Question:
  • Add baz to the staging area using git add -A, then commit with the message "Add bazz".
  • kartikmandar's Answer:
    Exercise Question:
  • Realizing there’s a typo in your commit message, change bazz to baz using git commit --amend.
  • kartikmandar's Answer:
    Exercise Question:
  • Run git log to get the SHA of the last commit, then view the diff using git show <SHA> to verify that the message was amended properly.
  • kartikmandar's Answer:
    Exercise Question:
  • The git log command shows only the commit messages, which makes for a compact display but isn’t particularly detailed. Verify by running git log -p that the -p option shows the full diffs represented by each commit.
  • kartikmandar's Answer:
    Exercise Question:
  • Under the h1 tag in Listing 1.6, use the p tag to add a paragraph consisting of the line “Call me Ishmael.” The result should appear as in Figure 1.6. (Don’t worry if you get stuck; we’ll incorporate the answer to this exercise in Section 1.6 (Listing 1.8).)
  • kartikmandar's Answer:
    Exercise Question:
  • Add the title “A whale of a greeting” to index.html. Browsers differ in how they display titles; the result in Safari is shown in Figure 1.8. (As of this writing, Safari doesn’t display the title unless there are at least two tabs, which is why there’s a second tab in Figure 1.8.)
  • kartikmandar's Answer:
    Exercise Question:
  • Commit the new title with a commit message of your choice. Verify using git log -p that the change was committed as expected.
  • kartikmandar's Answer:
    Exercise Question:
  • By pasting the contents of Listing 1.8 into an HTML validator, verify that it is not (quite) a valid web page.
  • kartikmandar's Answer:
    Exercise Question:
  • Using the validator, verify that the current index.html (with nonblank page title) is valid.
  • kartikmandar's Answer:
    Exercise Question:
  • On the GitHub page for your repo, click on “Commits” to see a list of your commits. Confirm that they match the results of running git log on your local system.
  • kartikmandar's Answer:
    Exercise Question:
  • At GitHub, click on the commit for adding HTML structure (Listing 1.10). Verify that the diff for the commit agrees with the one shown in Listing 1.9.
  • kartikmandar's Answer:
    Exercise Question:
  • In honor of shipping your first Git repo, drink a celebratory beverage of your choice (Figure 2.7).4
  • kartikmandar's Answer:
    Exercise Question:
  • Using the Markdown shown in Listing 2.3, add a line at the end of the README with a link to the official Git documentation.
  • kartikmandar's Answer:
    Exercise Question:
  • Commit your change with an appropriate message (Box 1.4). You don’t have to run git add. Why not?
  • kartikmandar's Answer:
    Exercise Question:
  • Push your change to GitHub. By refreshing your browser, confirm that the new line has been added to the rendered README. Click on the “official Git documentation” link to verify that it works.
  • kartikmandar's Answer:
    Exercise Question:
  • Click on the image link at GitHub to verify that the git push succeeded.
  • kartikmandar's Answer:
    Exercise Question:
  • At this point, the number of commits is large enough that the output of git log -p is probably too big to fit in your terminal window. Confirm that running git log -p drops you into a less interface for easier navigation.
  • kartikmandar's Answer:
    Exercise Question:
  • Use your knowledge of less commands to search for the commit that added the HTML DOCTYPE. What is the SHA of the commit?
  • kartikmandar's Answer:
    Exercise Question:
  • Commit the .gitignore file to your repository. Hint: Running git commit -am isn’t enough. Why not?
  • kartikmandar's Answer:
    Exercise Question:
  • Push your commit up to GitHub and confirm using the web interface that the push succeeded.
  • kartikmandar's Answer:
    Exercise Question:
  • Use the command git branch -d about-page to delete the topic branch. Confirm by running git branch that only the main branch is left.
  • kartikmandar's Answer:
    Exercise Question:
  • In Listing 3.3, we used git checkout -b to create a branch and check it out at the same time, but it’s also possible to break this into two steps. As a first step, use git branch to make a branch with the name test-branch. (This involves passing an argument to git branch, as in git branch <branch name>.) Then confirm that the new branch exists but isn’t currently checked out by running git branch without an argument.
  • kartikmandar's Answer:
    Exercise Question:
  • Check out test-branch and use touch to add a file with a name of your choice, then add and commit it to the repository.
  • kartikmandar's Answer:
    Exercise Question:
  • Check out the main branch and try deleting the test branch using git branch -d to confirm that it doesn’t work. The reason is that, in contrast to the about-page branch, the test branch hasn’t been merged into main, and by design -d doesn’t work in this case. Because we don’t actually want its changes, delete the test by using the related -D option, which deletes the branch in question even if its changes are unmerged.
  • kartikmandar's Answer:
    Exercise Question:
  • The git checkout -f trick works only with files that are staged for commit or are already part of the repository, but sometimes you want to get rid of new files as well. Using touch, create a file with a name of your choice, then git add it. Verify that running git checkout -f gets rid of it.
  • kartikmandar's Answer:
    Exercise Question:
  • Like many other Unix programs, git accepts both “short form” and “long form” options. Repeat the previous exercise with git checkout --force to confirm that the effects of -f and --force are identical. Extra credit: Double-check this conclusion by finding the “force” option in the output of git help checkout.
  • kartikmandar's Answer:
    Exercise Question:
  • As Alice, run git log to verify that the commit was pulled down correctly. Double-check the details using git log -p.
  • kartikmandar's Answer:
    Exercise Question:
  • The whale picture added in Listing 3.1 (Figure 3.1) requires attribution under the Creative Commons Attribution-NoDerivs 2.0 Generic license. As Alice, link the image to the original attribution page, as shown in Listing 4.1. Commit the result and push to GitHub.
  • kartikmandar's Answer:
    Exercise Question:
  • As Bob, pull in the changes from the previous exercise. Verify by refreshing the browser and by running git log -p that Bob’s repo has been properly updated.
  • kartikmandar's Answer:
    Exercise Question:
  • Change your default Git editor from Vim to Atom. Hint: Google for it. (This is an absolutely classic application of technical sophistication (Box 1.2): With a well-chosen Google search, you can often go from “I have no idea how to do this” to “It’s done” in under 30 seconds.)
  • kartikmandar's Answer:
    Exercise Question:
  • The polar bear picture added in Listing 4.3 (Figure 4.11) requires attribution under the Creative Commons Attribution 2.0 Generic license. As Alice, link the image to the original attribution page, as shown in Listing 4.8. Then run git commit -a without including -m and a command-line message. This should drop you into the default Git editor. Quit the editor without including a message, which cancels the commit.
  • kartikmandar's Answer:
    Exercise Question:
  • Run git commit -a again, but this time add the commit message “Add polar bear attribution link”. Then hit return a couple of times and add a longer message of your choice. (One example appears in Figure 4.17.) Save the message and exit the editor.
  • kartikmandar's Answer:
    Exercise Question:
  • Run git log to confirm that both the short and longer messages correctly appear. After pushing the changes to GitHub, navigate to the page for the commit to confirm that both the short and longer messages correctly appear.
  • kartikmandar's Answer:
    Exercise Question:
  • As Bob, pull in the changes to the About page. Verify by refreshing the browser and by running git log -p that Bob’s repo has been properly updated.
  • kartikmandar's Answer:
    Exercise Question:
  • Bob’s main branch doesn’t currently have Alice’s merge, so check out main as Bob and do a git pull. Confirm using git log that Alice’s merge commit is now present.
  • kartikmandar's Answer:
    Exercise Question:
  • Delete the fix-trademark branch locally. Do you need to use the -D option (Section 3.3.2), or is -d sufficient?
  • kartikmandar's Answer:
    Exercise Question:
  • Delete the remote fix-trademark branch on GitHub. Hint: If you get stuck, Google for it.
  • kartikmandar's Answer:
    Exercise Question:
  • On the About page, add a link back to index.html. Commit and push your change and verify that the link works on the production site.
  • kartikmandar's Answer:
    Exercise Question:
  • As covered in Learn Enough Command Line to Be Dangerous, two of the most important Unix commands are mv and rm. Git provides analogues of these commands, which have the same effect on local files while also arranging to track the changes. Experiment with these commands via the following sequence: Create a file with some lorem ipsum text, add & commit it, rename it with git mv & commit, then remove it with git rm & commit again. Examine the results of git log -p to see how Git handled the operations.
  • kartikmandar's Answer:
    Exercise Question:
  • To practice the process of making a new Git repository, make a second project called second_website in the repos directory. Create an index.html file with the content “hello, again!” and follow the steps (starting in Section 1.2) needed to deploy it to the live Web.
  • kartikmandar's Answer:
    Exercise Question:
  • Make a third, secret project called secret_project. Touch files called foo, bar, and baz in the main project directory, and then follow the steps to initialize the repository and commit the initial results. Then, to practice using a service other than GitHub, create a free private repository at Bitbucket.
  • kartikmandar's Answer:
    Exercise Question:
  • Create a branch called really-long-branch-name using git co -b.
  • kartikmandar's Answer:
    Exercise Question:
  • Switch back to the main branch using git co.
  • kartikmandar's Answer:
    Exercise Question:
  • Check out the branch really-long-branch-name using tab completion by typing git checkout r⇥ at the command-line prompt.
  • kartikmandar's Answer:
    Exercise Question:
  • What does your prompt look like? Verify that the correct branch name appears in the prompt.
  • kartikmandar's Answer:
    Exercise Question:
  • Check out the main branch using git co m⇥. (This shows that tab completion works with the co alias set up in Listing 4.13.) What does the prompt look like now?
  • kartikmandar's Answer:
    Exercise Question:
  • Use git branch -d r⇥ to delete really-long-branch-name, thus verifying that tab completion works with git branch as well as with git checkout. (In fact, tab completion works with most relevant Git commands.)
  • kartikmandar's Answer:

    Join the Mailing List

    Get occasional notifications about things like product discounts, blog posts, and new or updated tutorials. Unsubscribe at any time.