Git fatal: ‘origin’ does not appear to be a git repository Solution
a Git repository
is not associated with a remote repository. If you try to push changes to a remote repository without first specifying its location, you’ll encounter the “fatal: ‘origin’ does not appear to be a git repository” error.
This guide talks about why this error is raised and what it means. We’ll walk through an example of this error so you can figure out how to fix it.
fatal: ‘origin’ does not appear to be a git repository
git init command
creates a new Git repository. This command only initializes a folder as a Git repository. It does not link a repository to a remote repository.
Find Your Bootcamp Match
- Career Karma matches you with top tech bootcamps
- Access exclusive scholarships and prep courses
In contrast, the git clone command does link a local repository to a remote one. This is because Git knows where the code from a project came from and uses the location you cloned to guess where you are going to be pushing commits.
The “fatal: ‘origin’ does not appear to be a git repository” error occurs when you set up a new repository and try to commit code without first instructing Git on where the code should be pushed.
An Example Scenario
We’re going to create a new repository, ck-git.
Make a new folder and initialize the folder as a Git repository:
mkdir ck-git cd ck-git git init
We have navigated into our new ck-git folder then we initialized a Git repository inside that folder. Now, create a file called app.py with the following contents:
Our repository now has a file we can push to our remote repository. Before we can push our code, we need to
add our file to our repository
and commit that file:
git add app.py git commit -m "feat: Create app.py"
The first command adds app.py to the staging area. The second command
creates a commit
containing the changes made to all the files in the staging area.
Now that we’ve created a commit, we can push it to the master branch on our remote Git repo:
git push origin master
When we run this command, an error occurs:
"Career Karma entered my life when I needed it most and quickly helped me match with a bootcamp. Two months after graduating, I found my dream job that aligned with my values and goals in life!"
Venus, Software Engineer at Rockbot
'origin' does not appear to be a git repository fatal: Could not read from remote repository.
Make sure you have the correct access rights and the repository exists.
We have not told Git the location of the “origin” repository. We’ve initialized a new repository using “git init” and so our repository is not linked to any remote repository by default.
To fix this error, we need to manually tell Git where the remote version of our repository exists. Do this using the
git remote add command
git remote add origin https://github.com/career-karma-tutorials/ck-git
This command tells Git the remote called “origin” should be associated with a particular URL. Git now knows where the remote version of our repository exists.
Let’s try to push our code again:
git push origin master
The Git command line successfully pushes our code to our remote repository.
The “fatal: ‘origin’ does not appear to be a git repository” error occurs when you try to push code to a remote Git repository without telling Git the location of the remote repository.
To solve this error, use the git remote add command to add a remote to your project.
Now you have the knowledge you need to fix this error like a professional programmer.