WDI Fundamentals Unit 7
This exercise will allow you to practice using Git.
1) Open your terminal, and navigate to the
fundamentals directory you created earlier. Create a new directory within it called "git-practice."
cd to navigate into that new directory. You can make sure you're in the right place by using the
git init to create a Git repository in the
git init, make sure you're not already inside another Git repository. Type
git status. If you see
fatal: Not a git repository (or any of the parent directories): .git, then you know you're good to go, and you can safely run
git initwithin this folder.
Notice that there is now a
.git directory in
git-practice — you'll see it if you run the
ls -a command.
4) Create a new file called "README.txt," and run
git status. What output do you get?
5) Use the
git add README.txt command to add the new file to the staging area. Run
git status again — how has its output changed?
6) Now that you're satisfied with the changes you've staged, commit them using
git commit -m "...". Give the commit an appropriate message — remember, it should be short but descriptive.
7) Create a directory called "src," and add a couple of files to it.
8) Use the
add command, but add the
src directory instead of the individual files. Then, use the
command. See how both files have been staged? Go ahead and commit the addition of these new files to the repo.
9) Make a change to one of the files, and run
git diff to look at all the unstaged changes to our repo. What do you see?
add the changed file and type
git diff. What's changed? Why? What do you have to do to see a
diff of the changes in the staging area?
11) Now — without adding or committing — make another change to the same file you altered in Step 9. Look at the
status output and the
diff output. See how you can have both staged and unstaged changes, even when you’re talking about a single file?
commit all outstanding changes. Use the
log command to see all of the commits you've made so far.