Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

iTechGuides is reader-supported. When you buy through links on our site, we may earn an affiliate commission. As an Amazon Associate I earn from qualifying purchases. Learn more

Before you run git commit, confirm two things: which paths are staged, and what the staged patch actually contains. Most accidental commits of .env files, node_modules folders, or focused Jest tests happen because the author looked at the editor or at a list of changed files, not at the patch Git is about to record. The checklist below takes a few minutes and catches all three.

How do I check what I’m about to commit?

Git keeps three views of your work, and each command answers a different question. The working tree holds the files on disk. The index (also called the staging area) holds the content prepared for the next commit. HEAD is the most recent commit on your current branch. A normal git commit records what is in the index, not what is on disk.

Command What it compares What it answers
git status Index against HEAD; working tree against index; untracked paths not excluded by ignore rules Which paths are staged, changed but not staged, or new
git diff --cached Index against HEAD The exact patch the next ordinary git commit will record
git diff Working tree against index Edits you have not staged yet, which the next commit will not include

git status tells you which files are involved. git diff --cached tells you what changed inside them. The file list alone cannot show that a staged file contains a debugging line or a credential, so the staged patch is the check that matters. The git-status documentation describes the three categories above, and its -v option adds the staged textual changes to the status output.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Why is .env still showing up even though it’s in .gitignore?

A .gitignore pattern only applies to files Git is not already tracking. Git uses it to decide which untracked paths to ignore. If a file has ever been added to the index and committed, the ignore rule has no effect on it: edits to that file keep appearing in git status, and git commit -a will record them. Adding .env or node_modules to .gitignore therefore does not remove a copy that is already in the repository.

#1 Best Overall
Sale
Lexar D40E 128GB Dual USB 3.2 Gen 1 Type-C Jump Drive, Champagne Silver
  • USB-C 2-in-1 storage OTG: The Lexar JumpDrive Dual Drive D40E features USB Type-A and Type-C connectors in a slim, portable form factor for easy device compatibility
  • Transfer speeds up to 100MB/s: Based on internal testing, performance may vary depending upon the host device, interface, and usage conditions. 1MB=1,000,000 bytes
  • Plug and Play: Widely compatible with USB Type-C smartphones, tablets, laptops, Macs, and traditional Type-A devices, no software installation required. The 360° swivel design allows for easy switching between connectors without the hassle of losing a cap
  • Durable & Compact: The Lexar D40E USB memory stick features a metal enclosure, withstands temperatures from 0° to 50° C (32°F to 122°F), and is lightweight at 26g with dimensions of 70.4 x 16.9 x 11.7mm
  • Security & Warranty: Securely protects files using an advanced security software solution with 256-bit AES encryption. Backed by a Lexar 3-year limited warranty

This is why the symptom is confusing. The ignore rule looks correct, the file is still listed, and the reader assumes Git is malfunctioning. In fact Git is doing what the gitignore documentation describes: patterns specify intentionally untracked files, and tracked files are unaffected. Shared project patterns belong in the repository’s .gitignore. Patterns that apply only to your own machine can go in a local exclude file instead.

The fix is to stop tracking the file while keeping the copy on disk. Removing it from the index is a separate step from adding an ignore rule, and it is the step that needs a careful look at the staged result.

Keep in mind that removing a file from the index only changes future commits. Earlier commits still contain its contents. If a real secret was ever pushed, rotate that credential; removing the file alone does not make it unavailable.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Why are my Jest tests being skipped?

Jest’s test.only (alias it.only) tells Jest to run only the selected tests in that file. Every other test in the file is skipped. Jest’s documentation describes this as a debugging feature, and its API reference states: “Usually you wouldn’t check code using test.only into source control – you would use it for debugging, and remove it once you have fixed the broken tests.”

Rank #2
SANDISK 128GB Ultra Flair, USB-A Flash Drive, Up to 150MB/s Read Speeds
  • High-speed USB 3.0 performance of up to 150MB/s(1) [(1) Write to drive up to 15x faster than standard USB 2.0 drives (4MB/s); varies by drive capacity. Up to 150MB/s read speed. USB 3.0 port required. Based on internal testing; performance may be lower depending on host device, usage conditions, and other factors; 1MB=1,000,000 bytes]
  • Transfer a full-length movie in less than 30 seconds(2) [(2) Based on 1.2GB MPEG-4 video transfer with USB 3.0 host device. Results may vary based on host device, file attributes and other factors]
  • Transfer to drive up to 15 times faster than standard USB 2.0 drives(1)
  • Sleek, durable metal casing
  • Easy-to-use password protection for your private files(3) [(3)Password protection uses 128-bit AES encryption and is supported by Windows 7, Windows 8, Windows 10, and Mac OS X v10.9 plus; Software download required for Mac, visit the SanDisk SecureAccess support page]

The problem is visibility. If the one test that runs passes, the file can look green, and the skipped tests appear only as a skipped count in Jest’s summary. A focused marker committed to the repository therefore quietly reduces coverage for everyone who runs the suite. The same risk applies to Jasmine-style fit and fdescribe markers, which the checklist below also covers.

A focused run is useful, but it answers a narrower question. Running one file, or a set of tests related to changed source files, tells you those tests passed. It does not tell you that the rest of the suite passed, and it does not tell you what Git will commit.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Pre-commit checklist

  1. Inspect the status. Run:

    git status

    Read each section. Anything under “Changes to be committed” will go into the next commit. Anything under “Changes not staged for commit” or “Untracked files” will not, unless you stage it. Stop if you see .env, a key file, a node_modules/ directory, or a build artifact you did not intend to touch.

    Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
  2. Review the staged patch. Run:

    git diff --cached --stat
    git diff --cached

    The --stat form gives a file-level summary, which helps you spot unexpected paths. It does not show content, so read the full patch before committing. Look for credentials, local paths, debugging output, and focused test markers.

    Rank #3
    2 Pack 64GB USB Flash Drive USB 2.0 Thumb Drives Jump Drive Fold Storage Memory Stick Swivel Design - Black
    • What You Get - 2 pack 64GB genuine USB 2.0 flash drives, 12-month warranty and lifetime friendly customer service
    • Great for All Ages and Purposes – the thumb drives are suitable for storing digital data for school, business or daily usage. Apply to data storage of music, photos, movies and other files
    • Easy to Use - Plug and play USB memory stick, no need to install any software. Support Windows 7 / 8 / 10 / Vista / XP / Unix / 2000 / ME / NT Linux and Mac OS, compatible with USB 2.0 and 1.1 ports
    • Convenient Design - 360°metal swivel cap with matt surface and ring designed zip drive can protect USB connector, avoid to leave your fingerprint and easily attach to your key chain to avoid from losing and for easy carrying
    • Brand Yourself - Brand the flash drive with your company's name and provide company's overview, policies, etc. to the newly joined employees or your customers
  3. Check for ignored paths that Git still tracks. Run:

    git ls-files -ci --exclude-standard

    This lists files that match an ignore rule but are still in the index. For each unwanted file, confirm which rule covers it with:

    git check-ignore -v .env

    Make sure the rule is in .gitignore, then remove the tracked copy from the index while keeping the local file. For a single file:

    Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
    git rm --cached .env

    For a directory such as node_modules:

    git rm -r --cached node_modules

    Both commands stage a deletion and leave the files on disk. Afterwards, inspect the staged removal with git diff --cached --name-status. You should see D entries only for the paths you intended to untrack. If your project has no ignore rule yet, add one before running the removal, or the file may reappear in the next git add -A.

    Rank #4
    SIMMAX 32GB Memory Stick USB 2.0 Flash Drives Swivel Thumb Drive Pen Drive (32GB Purple)
    • GOOD VALUE PACKAGE - 1 Pack 32GB Memory Stick USB 2.0 Flash Drives with great cost performance and high quality.
    • BIG CAPACITY - The available capacity: 29.10GB-29.8GB, You can save the data of movies, music, photos, designs, programs, manuals, handouts in a high speed.Good performance in digital data storing, transferring and sharing with families, friends, workmates, clients and machines.
    • EASY TO USE & PLUG AND WORK - Support windows 7 / 8 / 10 / Vista / XP / 2000 / ME / NT Linux and Mac OS, Compatible with USB2.0 and below.
    • TWISTTURN DESIGN & EASY CARRY - The metal clip rotates 360° round the ABS plastic body which with rubber oil skin feeling finish. The capless design can avoid lossing of cap, and providing efficient protection to the USB port.
    • WARRANTY & SUPPORT - SIMMAX logo is laser printed on the USB connector surface, our products are of good quality and we promise that any problem about the product within one year since you buy.
  4. Search for focused tests. Check the staged changes first:

    git diff --cached -G'b(it|test|describe).only(|bfit(|bfdescribe('

    Then search the tracked files, which catches markers that were committed earlier:

    git grep -nE 'b(it|test|describe).only(|b(fit|fdescribe)('

    Remove any marker you were using for debugging and keep the other tests in the file. If a marker is intentional for a reason the team has agreed on, leave it and note that in the commit message.

    Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
  5. Run the appropriate tests. Check which Jest version the project uses before you rely on version-specific options:

    Best Value
    IMEASON Swivel Design 16GB USB Flash Drive with Keychain, USB 2.0 Portable Thumb Drive Memory Stick, FAT32 Format Flashdrive for Data Storage, Photos, Music, Files (Black, 16 GB)
    • 【16GB Flash Drive】USB flash drives with 16GB capacity, meet your needs of daily use on work, school, home and travelling for photos, music, videos, files storage and transfer. IMEASON thumb drives can be used to store different files, easy to data backup.
    • 【Metal Swivel Cap Design】USB thumb drive is metal swivel cover provides extra protection for the usb thumbdrive connector, no usb drive cap to lose; keychain design makes it easier to carry without worrying lose it.
    • 【Wide Compatibility】USB drive supports Windows 7/8/10/11 / Vista / XP / Unix / 2000 / ME / NT Linux and Mac OS, also Supports USB 2.0 and 1.1 ports. USB Stick support TV, desktop, notebook computer, car, audio and other device. The USB Memory Stick is your great data storage and transfer companion with traveling and working.
    • 【Easy to use】usb memory stick is plug and play without any software installation. Just simply plug the Flashdrive into the port of your USB-compatible devices such as computer, laptop to start data storage or transmission.
    • 【What You Get】16 GB USB Flash Drive Thumb Drive, The default format of the usb storage flash drive is FAT32.
    npx jest --version

    On Jest 30.0, the CLI documentation says –findRelatedTests runs tests related to the source files you name, and it lists pre-commit hook integration as a use. A targeted run looks like this:

    npx jest --findRelatedTests src/cart/total.js src/cart/discount.js

    Use it as a fast check on the code you changed. Run the full suite before merging or when the change touches shared code. A passing targeted run does not prove that the whole suite passed.

  6. Fix, stage, and check again. Correct what the checks found. To stage only some edits inside a file, use interactive partial staging:

    Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
    git add -p path/to/file.js

    Edits made after staging are not included until you stage them again. Once the index contains exactly what you want, repeat the checks on the staged result:

    git status
    git diff --cached

    Confirm that no secret, dependency directory, or focused test marker remains in the staged patch. Only then run git commit.

Git’s git-add documentation covers partial staging in more depth, including how to unstage a hunk if you add the wrong one.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.