Skip to content

Instantly share code, notes, and snippets.

@mkhlz
Created March 5, 2026 14:19
Show Gist options
  • Select an option

  • Save mkhlz/e09859ff766f5a3a1a7e2b6014298536 to your computer and use it in GitHub Desktop.

Select an option

Save mkhlz/e09859ff766f5a3a1a7e2b6014298536 to your computer and use it in GitHub Desktop.

Assignment Part 2: Leveling Up Your Git Skills & Keeping Secrets

Objective: In this assignment, you will add new files to your existing project, learn what a .gitignore file is, and use it to prevent Git from uploading sensitive files or junk files to your public GitHub profile.

Prerequisites: Completion of Part 1 (You should have your git-assignment folder on your Desktop, linked to GitHub).


Phase 1: Get Back to Your Workspace

First, we need to open Git Bash and navigate back into your project folder.

Step 1: Open Git Bash from your Windows Start Menu. Step 2: Navigate to your project folder on the Desktop by typing:

cd ~/Desktop/git-assignment

Step 3: Make sure everything is up to date by checking your status:

git status

(It should say "nothing to commit, working tree clean".)


Phase 2: Add New Project Files

Let's add some actual content to your repository.

Step 1: Let's create a couple of text files for your project. Type the following commands:

echo "Git is awesome!" > notes.txt
echo "1. Learn Git 2. Drink Coffee" > todo.txt

Step 2: Run git status. You will see notes.txt and todo.txt listed in red as "Untracked files". This is normal! Git sees them but isn't saving them yet. Do not commit them just yet.


Phase 3: The Problem (Files You Don't Want to Track)

Sometimes, you create files in your project folder that you never want to send to GitHub. Examples include:

  • Passwords or secret API keys
  • Personal notes
  • Messy system log files created by your computer

Step 1: Let's pretend you have a file with a secret password, and a messy log file. Create them by typing:

echo "MY_SECRET_PASSWORD=12345" > passwords.env
echo "Error at line 42" > debug.log

Step 2: Run git status again. Notice that passwords.env and debug.log are sitting there in red. If you were to run git add . right now, your secret password would be staged to go to the internet! We need to stop Git from seeing these files.


Phase 4: The Magic of .gitignore

A .gitignore file is a special, hidden text file. Any file or folder name you type inside it will be completely invisible to Git.

Step 1: Create the .gitignore file and open it in Windows Notepad directly from Git Bash:

notepad .gitignore

(Note: Make sure there is a "dot" at the very beginning of the word gitignore. A Notepad window will pop up asking if you want to create the file. Click Yes.)

Step 2: In the Notepad window, type the exact names of the files you want Git to ignore. Type the following on separate lines:

passwords.env
*.log

(Why *.log? The asterisk * is a wildcard. It tells Git to ignore ANY file that ends in .log, no matter what its name is!)

Step 3: Save the file in Notepad (Ctrl + S) and close the Notepad window.


Phase 5: Test Your .gitignore

Let's see if it worked.

Step 1: Go back to your Git Bash window and run your favorite command:

git status

Step 2: Look closely at the output.

  • You will see .gitignore, notes.txt, and todo.txt in red.
  • The magic: passwords.env and debug.log have completely disappeared from the list! Git is now ignoring them. Your secrets are safe.

Phase 6: Save and Push to GitHub

Now let's formally save our new files and our .gitignore file, and send them to GitHub.

Step 1: Stage all the safe files:

git add .

Step 2: Commit them with a descriptive message:

git commit -m "Added project notes and configured gitignore"

Step 3: Push the changes to GitHub:

git push

Phase 7: Verify and Submit

Step 1: Go to your web browser, open your GitHub repository, and refresh the page. Step 2: Verify that notes.txt, todo.txt, and .gitignore are there. Step 3: Verify that passwords.env and debug.log are NOT there.

📝 How to Submit Your Assignment:

  1. Take a screenshot of your GitHub repository page showing the new files.
  2. Submit the screenshot along with the link to your repository.
  3. Answer this short question in your submission: Why is it important to use a .gitignore file before running git add .?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment