Curious Minds

Clear answers to science and history questions

Why Is Git Not Working? Common Causes & Fixes

· 6 min read · Science

Git is not working usually because it is not installed or not on your system's PATH, because you are running the command outside a Git repository, or because of a configuration or permission problem. The error message you see points to which of these it is, so the first step is always to read it carefully rather than retyping the same command.

Start With the Exact Error Message

Git reports problems in fairly specific language, and the wording tells you which layer failed. A shell that says git: command not found (or 'git' is not recognized as an internal or external command on Windows) never reached Git at all. A message like fatal: not a git repository (or any of the parent directories): .git means Git ran fine but you are in the wrong folder. Errors containing Permission denied, could not read from remote repository, or detected dubious ownership come from Git itself but concern access rights or repository ownership. Copy the first line of the error into a search engine; the phrasing is standard and almost always maps to a known cause.

Installation and PATH Problems

The most common reason Git "does not work" on a new machine is that it was never installed, or it was installed but the shell cannot find it. Git is a separate program from your editor, your terminal, and your operating system, so installing a code editor does not install Git.

  • Check whether it exists: run git --version. A version number means Git is installed and reachable; an error means it is not.
  • Windows: install Git for Windows, then open a new terminal window. Existing terminals keep the old PATH and will still say the command is not found.
  • macOS: running git --version may trigger a prompt to install the command line developer tools, which include Git.
  • Linux: install it through your distribution's package manager (for example apt install git on Debian-based systems).
  • PATH issues: if Git is installed but still not found, its installation directory is missing from the PATH environment variable. On Windows this is often because the installer's PATH option was left unchecked.

A related trap: some graphical Git clients bundle their own copy of Git. Git may work inside the client but not in a normal terminal, because the bundled binary was never added to PATH.

You Are Probably Not in a Repository

Git commands such as status, log, add, and commit operate on a repository, which is a folder containing a hidden .git directory. If you open a terminal in your home folder or in a project you downloaded as a ZIP file, there is no .git directory and Git correctly refuses to act. A ZIP download from a hosting site contains the files but not the history, so it is not a clone.

The fix is to move into the project folder with cd, or to create a repository with git init if you are starting fresh. You can confirm where you are with pwd (macOS and Linux) or cd with no arguments (Windows). If you cloned a repository, remember that the clone creates a subfolder named after the project; you must enter that subfolder before Git commands work.

Identity, Configuration, and First-Commit Errors

Git refuses to create a commit until it knows who you are. The message reads roughly: Please tell me who you are, followed by instructions to set user.name and user.email. This is not a bug; commit history records an author, and Git will not invent one. Set them once with git config --global user.name "Your Name" and git config --global user.email "you@example.com".

Other configuration problems produce confusing behaviour rather than outright failure:

  • A wrong core.autocrlf setting on Windows can make every file appear modified after a checkout, because line endings are being converted.
  • A stale credential helper can keep sending an old password, producing repeated authentication failures even after you change it.
  • An editor configured as core.editor that is not actually installed makes commands that open an editor appear to hang or fail.

Running git config --list --show-origin shows every setting and which file it came from, which is the fastest way to spot a stray value in a system or global config.

Authentication and Remote Access Failures

When git push or git pull fails, the problem is usually between your machine and the remote server, not in Git's local logic. Typical messages include Authentication failed, Permission denied (publickey), and Could not resolve host.

  • Password authentication: many hosting services no longer accept account passwords over HTTPS; they require a personal access token or an SSH key instead.
  • SSH keys: the key must be added to your account and present in the SSH agent or the default key location. Test the connection with ssh -T git@host before blaming Git.
  • Network and proxy: Could not resolve host means DNS failed, and corporate proxies often need explicit configuration via http.proxy.
  • Wrong remote URL: git remote -v shows where pushes actually go. A typo in the URL produces errors that look like permission problems.

Permission, Ownership, and Lock Problems

Git writes files constantly, so file-system permissions matter. On shared or copied directories, Git may report detected dubious ownership in repository. This is a safety check introduced because a repository owned by a different user account could contain malicious configuration. The correct fix is to change ownership of the folder to your user, not to disable the check globally.

Another frequent failure is the lock file: Unable to create index.lock: File exists. Git creates lock files while writing, and if a previous command crashed or was killed, the lock can be left behind. Confirm no Git process is still running, then delete the stale index.lock inside the .git directory. Deleting lock files while another Git process is active can corrupt the index, so check first.

Merge Conflicts and Detached HEAD

Some situations are not errors at all but states Git expects you to resolve. A merge conflict stops with CONFLICT markers in the affected files; you edit the files, remove the markers, and run git add followed by git commit. A detached HEAD means you checked out a specific commit rather than a branch, so new commits are not attached to any branch. Git warns about this clearly; the fix is to create a branch with git switch -c new-branch before committing, or to switch back to an existing branch.

Frequently Asked Questions

Why does my terminal say git is not recognized?

Git is either not installed or its installation folder is not on the PATH. Install Git, then close and reopen the terminal so the updated PATH is loaded. On Windows, rerun the installer and choose the option that adds Git to the PATH.

Why does Git say "not a git repository"?

Your current folder, and none of its parent folders, contains a .git directory. Move into the project folder, or run git init if the project has no repository yet. A project downloaded as a ZIP archive has no repository.

Why can't Git push my changes?

Usually authentication or permissions. Check the remote URL with git remote -v, confirm you have write access to the repository, and verify your credentials or SSH key. The exact error text distinguishes a rejected password from a rejected key.

Why does Git keep asking for my password?

No credential helper is configured, or the stored credential is outdated. Configure a credential helper for your platform, or switch to SSH keys, which avoid repeated password prompts.

Why does Git show files as modified when I changed nothing?

Line-ending conversion is the usual cause, especially when a repository is used across Windows and Unix-like systems. Check the core.autocrlf setting and whether the repository includes a .gitattributes file that defines line endings.

Is it safe to delete the .git folder to fix problems?

No. The .git folder contains the entire history, branches, and configuration. Deleting it turns the project into plain files with no version control. If the repository is damaged, copy the folder first and attempt recovery rather than deleting it.

In this article
  1. Start With the Exact Error Message
  2. Installation and PATH Problems
  3. You Are Probably Not in a Repository
  4. Identity, Configuration, and First-Commit Errors
  5. Authentication and Remote Access Failures
  6. Permission, Ownership, and Lock Problems
  7. Merge Conflicts and Detached HEAD
  8. Frequently Asked Questions