Common Git Errors and Solutions

1. fatal: not a git repository

fatal: not a git repository (or any of the parent directories): .git

Cause

The directory is not under Git version control (git init was not run, or the .git folder was deleted).

So…


This content originally appeared on DEV Community and was authored by Kazutora Hattori

1. fatal: not a git repository

fatal: not a git repository (or any of the parent directories): .git

Cause

The directory is not under Git version control (git init was not run, or the .git folder was deleted).

Solution

Initialize the repository with git init.

2. error: src refspec main does not match any

error: src refspec main does not match any

Cause

You ran git push origin main when the main branch did not exist.

Solution

git branch -M main # Rename the branch to main
git add . # Stage files
git commit -m “Initial commit” # Make the first commit
git push -u origin main # Push to GitHub

3. fatal: ‘origin’ does not appear to be a git repository

fatal: ‘origin’ does not appear to be a git repository

Cause

The remote (origin) is not configured.

Solution

Create a repository on GitHub

Link it to your local machine

git remote add origin https://github.com/ユーザー名/リポジトリ名.git
git push -u origin main

Key Points

git init → Put local under Git management

git remote add origin ... → Link to GitHub

git branch -M main → Align local and GitHub default branch names

Cannot push without commits

This enables pushing CI/CD files like .github/workflows/main.yml

Summary

Reorganized for clarity.


This content originally appeared on DEV Community and was authored by Kazutora Hattori


Print Share Comment Cite Upload Translate Updates
APA

Kazutora Hattori | Sciencx (2025-09-13T07:45:54+00:00) Common Git Errors and Solutions. Retrieved from https://www.scien.cx/2025/09/13/common-git-errors-and-solutions/

MLA
" » Common Git Errors and Solutions." Kazutora Hattori | Sciencx - Saturday September 13, 2025, https://www.scien.cx/2025/09/13/common-git-errors-and-solutions/
HARVARD
Kazutora Hattori | Sciencx Saturday September 13, 2025 » Common Git Errors and Solutions., viewed ,<https://www.scien.cx/2025/09/13/common-git-errors-and-solutions/>
VANCOUVER
Kazutora Hattori | Sciencx - » Common Git Errors and Solutions. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2025/09/13/common-git-errors-and-solutions/
CHICAGO
" » Common Git Errors and Solutions." Kazutora Hattori | Sciencx - Accessed . https://www.scien.cx/2025/09/13/common-git-errors-and-solutions/
IEEE
" » Common Git Errors and Solutions." Kazutora Hattori | Sciencx [Online]. Available: https://www.scien.cx/2025/09/13/common-git-errors-and-solutions/. [Accessed: ]
rf:citation
» Common Git Errors and Solutions | Kazutora Hattori | Sciencx | https://www.scien.cx/2025/09/13/common-git-errors-and-solutions/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.