Learn Enough Society
Certificate of Course CompletionThis page certifies that kartikmandar has completed Learn Enough Git to Be Dangerous! 🎉
git help
at the command line. What is the first command listed?
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
.
~/.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.
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.)
ls
on the hidden directory and guess the name of the main Git configuration file. Use cat
to dump its contents to the screen.
touch
command, create empty files called foo
and bar
in your repository directory.
git add foo
, add foo
to the staging area. Confirm with git status
that it worked.
git commit -m
and an appropriate message, add foo
to the repository.
git add bar
, add bar
to the staging area. Confirm with git status
that it worked.
git commit
without the -m
option. Use your Vim knowledge to add the message “Add bar”, save, and quit.
git log
, confirm that the commits made in the previous exercises worked correctly.
touch
to create an empty file called baz
. What happens if you run git commit -am "Add baz"
?
baz
to the staging area using git add -A
, then commit with the message "Add bazz"
.
bazz
to baz
using git commit --amend
.
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.
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.
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).)
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.)
git log -p
that the change was committed as expected.
index.html
(with nonblank page title) is valid.
git log
on your local system.
git add
. Why not?
git push
succeeded.
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.
less
commands to search for the commit that added the HTML DOCTYPE
. What is the SHA of the commit?
.gitignore
file to your repository. Hint: Running git commit -am
isn’t enough. Why not?
git branch -d about-page
to delete the topic branch. Confirm by running git branch
that only the main
branch is left.
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.
test-branch
and use touch
to add a file with a name of your choice, then add and commit it to the repository.
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.
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.
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
.
git log
to verify that the commit was pulled down correctly. Double-check the details using git log -p
.
git log -p
that Bob’s repo has been properly updated.
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.
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.
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.
git log -p
that Bob’s repo has been properly updated.
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.
fix-trademark
branch locally. Do you need to use the -D
option (Section 3.3.2), or is -d
sufficient?
fix-trademark
branch on GitHub. Hint: If you get stuck, Google for it.
index.html
. Commit and push your change and verify that the link works on the production site.
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.
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.
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.
really-long-branch-name
using git co -b
.
main
branch using git co
.
really-long-branch-name
using tab completion by typing git checkout r⇥
at the command-line prompt.
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?
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.)
Get free access to all 10 Learn Enough courses (including the Ruby on Rails Tutorial) for 7 days!
We require a credit card for security purposes, but it will not be charged during the trial period. After 7 days, you will be enrolled automatically in the monthly All Access subscription.
BUT you can cancel any time and still get the rest of the 7 days for free!
All Learn Enough tutorials come with a 60-day 100% money-back guarantee.