WDI Fundamentals

WDI Fundamentals Unit 7


Your Turn Your Turn

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."

2) Use cd to navigate into that new directory. You can make sure you're in the right place by using the pwd command.

3) Use git init to create a Git repository in the git-practice directory.


Before running 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 init within 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 git status 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?

10) Next, 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?

12) Finally, add and commit all outstanding changes. Use the log command to see all of the commits you've made so far.


On to the next lesson!