The assignments listed here should take you approximately 55 total minutes.
To start this assignment, click the button in the upper right-hand corner that says Fork. This is now your copy of the document. Click the Edit button when you're ready to start adding your answers. To save your work, click the green button in the bottom right-hand corner. You can always come back and re-edit your gist.
Need help? You can go back to the files/directories portion of the lesson here.
Scroll down to the bottom of this page and look at the image of the directories and files. Use commands in your terminal to create the directories and files structured exactly how they appear in the image.
When you're done, type history
to see your commands. Copy and paste the commands that were used to create the directory and files:
107 mkdir session_3_practice
108 cd session_3_practice
109 touch budget.csv
110 touch mentors.txt
111 mkdir notes
112 cd notes
113 touch git_notes.txt
114 touch command_line_notes.txt
115 cd ..
116 mkdir practice
117 cd practice
118 touch git_practice.txt
119 mkdir projects
120 cd projects
121 touch game.js
Since this is just a practice directory, feel free to remove the parent directory session_3_practice
when you're done with this exercise.
You can reference the files/directories portion of the lesson here.
Follow the steps below to practice the git workflow. Be ready to copy-paste your terminal output as confirmation of your practice.
- Create a directory called
git_homework
. Inside of there, create a file calledquotes.txt
. - Initialize the directory
- Check the git status
- Add your
quotes.txt
file to the staging area - Check the git status
- Create an initial commit
- Check the status
- Add your favorite quote to the
quotes.txt
file - Check the status
- Check the diff
- Add the changes to the staging area
- Commit the new changes
- Check the status
- Show the log in oneline (yes,
oneline
, not a spelling error) format
Copy and paste all of the terminal text from this process below (not just the history):
Last login: Sun Apr 5 15:55:09 on ttys000
chaddickerson@Chads-MacBook-Pro ~ % mkdir git_homework
chaddickerson@Chads-MacBook-Pro ~ % cd git_homework
chaddickerson@Chads-MacBook-Pro git_homework % touch quotes.txt
chaddickerson@Chads-MacBook-Pro git_homework % git init
Initialized empty Git repository in /Users/chaddickerson/git_homework/.git/
chaddickerson@Chads-MacBook-Pro git_homework % git status
On branch master
No commits yet
Untracked files:
(use "git add <file>..." to include in what will be committed)
quotes.txt
nothing added to commit but untracked files present (use "git add" to track)
chaddickerson@Chads-MacBook-Pro git_homework % git add quotes.txt
chaddickerson@Chads-MacBook-Pro git_homework % git status
On branch master
No commits yet
Changes to be committed:
(use "git rm --cached <file>..." to unstage)
new file: quotes.txt
chaddickerson@Chads-MacBook-Pro git_homework % git commit -m 'Initial commit'
[master (root-commit) f82dca0] Initial commit
1 file changed, 0 insertions(+), 0 deletions(-)
create mode 100644 quotes.txt
chaddickerson@Chads-MacBook-Pro git_homework % git status
On branch master
nothing to commit, working tree clean
chaddickerson@Chads-MacBook-Pro git_homework % atom .
chaddickerson@Chads-MacBook-Pro git_homework % git status
On branch master
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git restore <file>..." to discard changes in working directory)
modified: quotes.txt
no changes added to commit (use "git add" and/or "git commit -a")
chaddickerson@Chads-MacBook-Pro git_homework % git diff
diff --git a/quotes.txt b/quotes.txt
index e69de29..2cfff37 100644
--- a/quotes.txt
+++ b/quotes.txt
@@ -0,0 +1 @@
+If you spend too much time thinking about a thing, you'll never get it done. Bruce Lee
chaddickerson@Chads-MacBook-Pro git_homework % git add quotes.txt
chaddickerson@Chads-MacBook-Pro git_homework % git status
On branch master
Changes to be committed:
(use "git restore --staged <file>..." to unstage)
modified: quotes.txt
chaddickerson@Chads-MacBook-Pro git_homework % git diff
chaddickerson@Chads-MacBook-Pro git_homework % git diff quotes.txt
chaddickerson@Chads-MacBook-Pro git_homework % ls
quotes.txt
chaddickerson@Chads-MacBook-Pro git_homework % git status
On branch master
Changes to be committed:
(use "git restore --staged <file>..." to unstage)
modified: quotes.txt
chaddickerson@Chads-MacBook-Pro git_homework % git commit -m 'made changes to quotes'
[master e283538] made changes to quotes
1 file changed, 1 insertion(+)
chaddickerson@Chads-MacBook-Pro git_homework % git status
On branch master
nothing to commit, working tree clean
chaddickerson@Chads-MacBook-Pro git_homework % oneline
zsh: command not found: oneline
chaddickerson@Chads-MacBook-Pro git_homework % git log oneline
fatal: ambiguous argument 'oneline': unknown revision or path not in the working tree.
Use '--' to separate paths from revisions, like this:
'git <command> [<revision>...] -- [<file>...]'
chaddickerson@Chads-MacBook-Pro git_homework % git log --pretty=oneline
e283538e98404e50c666002cb4806cbad6c1428c (HEAD -> master) made changes to quotes
f82dca0b0d79c7bf9abbe4af1b06e17c02bf9ae0 Initial commit
chaddickerson@Chads-MacBook-Pro git_homework % history
139 git commit -m 'Initial commit'
140 git status
141 atom .
142 git status
143 git diff
144 git add quotes.txt
145 git status
146 git diff
147 git diff quotes.txt
148 ls
149 git status
150 git commit -m 'made changes to quotes'
151 git status
152 oneline
153 git log oneline
154 git log --pretty=oneline
chaddickerson@Chads-MacBook-Pro git_homework %
IMPORTANT: Do not remove this git_homework
directory. You will be using this directory during Thursday's session.
Look at the template below for a CardboardBox
class. Fill in missing blanks with additional attributes and methods.
Class: CardboardBox
Attributes:
- width (integer)
- depth (integer)
- height (integer)
- color (string)
Methods:
- break_down
- stack
- fill
- empty
-
Make sure that your shell is set to zsh by running the following command:
$ chsh -s /bin/zsh
. Remember to omit the$
! Note that macOS Catalina and later operating systems already use zsh as the default shell. -
Watch this video and follow each step to modify your own
zshrc
configuration file. As mentioned in the video, you will need this snippet below:
# Load version control information
autoload -Uz vcs_info
precmd() { vcs_info }
# Format the vcs_info_msg_0_ variable
zstyle ':vcs_info:git:*' formats '%b'
# Determine if current working directory is a git repository
git_branch_color() {
if current_git_status=$(git status 2> /dev/null); then
parse_git_dirty
else
echo ""
fi
}
# Change branch color if working tree is clean
parse_git_dirty() {
if current_git_status=$(git status | grep 'Changes to be committed:\|Untracked files:\|modified:|deleted:' 2> /dev/null); then
echo "%F{red}"
else
echo "%F{green}"
fi
}
# Set up the prompt (with git branch name)
setopt PROMPT_SUBST
PROMPT='%F{white}%d $(git_branch_color)${vcs_info_msg_0_} %f$'
If you have any questions, comments, or confusions that you would an instructor to address, list them below:
-
If time permits and you want extra git practice and alternative explanations (it's often beneficial to have something explained in many different ways), check out Codecademy's Git Course, particularly the first free item on the syllabus, "Basic Git Workflow". In Mod 0, we will not cover anything beyond Codecademy's intro section; however, you are welcome to check out the other git lessons listed on the syllabus if you want a head start.
-
This course is how I personally learned command line. If time permits, I highly recommend reading and practicing.
-
Also recommended by Jeff Casimir: Michael Hartl's Learn Enough Command Line.
-
Add tab completion to make your life easier: Type Less. Do More.
@chad-dickerson
Everything looks good to me! You'll get more practice using the terminal and making commits as you complete your capstone. I'd highly recommend a little research on ‘tab complete’ if you aren't using tab to auto-complete file and directory names in your terminal- familiarizing yourself with this early on makes life much easier!