Using Gitigore

Gitignore Exercises

Exercise 1

  • Change directories into your home directory
  • Make a new directory called git_practice
  • Initialize this as a repo
  • Use VS Code to make new file called .gitignore (code .gitignore)
  • git status from your terminal to see what's red/green
  • git add .gitignore
  • git commit -m "Add empty gitignore"
  • Use VS Code to make new file called secrets.txt (code secrets.txt)
    • add a pretend username and pretend password
  • git status from your terminal to see what's red/green
  • Open up .gitignore and add secrets.txt as its own line.
    • So, the only line of text is secrets.txt
    • git add .gitignore
    • git commit -m "add secrets.txt to gitignore"
  • git status to see what's red/green and the state of things
  • Try to git add secrets.txt
  • Make a repo on called git_practice
  • Add this remote to your local repo
  • git push your work.

Exercise 2

  • From your ~/git_practice directory, open up your .gitignore file
  • Add the line more_secrets.txt to your .gitignore file
  • Run git status
  • Now use VS Code to create a file called more_secrets.txt
  • Now do git add .gitignore and git commit -m "add more_secrets to gitignore"
  • Run git status to see the state of things
  • Now push your commit and check your repo on GitHub. What happed? What do you see?

Exercise 3

  • Run code ~/.gitignore_global to open up your global gitignore file. Add the following lines:

  • Next, run git config --global core.excludesfile ~/.gitignore_global from your terminal

Now it's time to confirm that Exercise 3 is done.

  • cd ~/git_practice
  • code to create an
  • Inside of, add the following lines
    host = "example_host_ip"
    username = "example_username"
    password = "example_password"
  • Save/exit VS code.
  • Now do git status
  • Do you see that git is tracking your file?
  • If it's showing in git status, why is that the case? Double check any spelling in the filename and your global gitignore.
Using Gitigore
Share this