Software⏱️ 2 min read📅 2026-05-31

How to Fix: How to fix: error: '<filename>' does not have a commit checked out fatal: adding files failed when inputting "git add ." in command prompt

GitLab repository issue with uncommitted file addition.

Quick Answer: Try using "git checkout -b" to create a new branch, then switch to it and try adding the file again.

The error message you're encountering suggests that the file you're trying to add to your Git repository doesn't have a commit checked out. This can be due to several reasons, such as working on an unpushed branch or having local changes not committed yet.

⚠️ Common Causes

  • Working on an unpushed branch or having local changes not committed yet.

🛠️ Step-by-Step Verified Fixes

Method 1: Revert Local Changes

  1. Step 1: Use the command `git checkout --theirs ` to revert local changes.

Method 2: Switch to a Different Branch

  1. Step 1: Use the command `git checkout master` (or whatever branch you want to switch to) and then `git add `.

🎯 Final Words

To avoid this issue in the future, always make sure to commit your changes before adding new files to your repository. Additionally, if you're working on a feature branch and need to add files from another branch, consider using `git merge` or `git subtree add` instead of `git add .

Did this fix your problem?

If not, try searching for specific error codes.

🔍 Search Error Database

❓ Frequently Asked Questions