How to Fix Origin Does Not Appear to Be A Git Repository

As a GitHub user, running into errors here and there is inevitable – whether you’re an expert or novice – what’s important is finding your way out of the errors. For example, say you run into the ‘origin does not appear to be a git repository’ error, you could be tempted to try out different codes hoping that one might fix it, but that would be the wrong move.

Since you’re reading this, you’ve already made the best first step. This article carefully highlights the causes and best fixes for the ‘origin does not appear to be a git repository’ error. It also enumerates vital information about Git repositories that you might want to check out.

What Causes The “Does Not Appear to Be A Git Repository” Error?

The ‘origin does not appear to be a git repository’ error occurs when the location of a remote repository is not specified before changes are pushed to it. Although by default, a local repository is not linked to the remote repository, you would have to link them yourself before pushing any codes. By this understanding, you cannot push or commit changes to the repository before linking the local and remote repositories because Git does not know where you are trying to push or commit to.

When you use the ‘git init’ command to create a repo, you need to use the ‘git remote add origin’ command to link your repo’s remote and local versions. Otherwise, pushing or committing changes will return the ‘origin does not appear to be a git repository’ error.

However, if you clone the remote repository using the ‘git clone’ command, it will automatically be linked to the local repository. The ‘git clone’ command allows Git to know the project’s location or remote repo, so when you push or commit your changes, Git knows what to do. Note that the local and remote repositories are not two different repos; they are merely two versions of the same repo.

Another reason why the ‘origin does not appear to be a git repository’ error appears is because of an incorrect URL. For example, when running the ‘git remote add origin’ command, you might have made a mistake in the URL used, which can cause the error. Also, if you are trying to push to a GitHub fork rather than the GitHub repo itself, you might have forgotten to fork it before trying to push to it.

How to Fix Origin Does Not Appear to Be A Git Repository – Working Fixes to Try

To fix the ‘origin does not appear to be a git repository’ error, you can try adding or linking the remote repo to the local version with the ‘git remote add origin’ command. To do this;

  1. Go to github.com and sign in to your account
  2. Locate the repo you want to clone and click on it to open
  3. Then, note down the URL of the page
  4. Run git remote add origin https://github.com/user/remote-repo, replacing the URL in the command with the URL of the remote repository you noted down
  5. You can also replace user and remote-repo in the URL above with your username and repository name, respectively
  6. Then, run git push origin master to push your changes properly

Fix 2: Git Clone Instead

Another way to fix the ‘origin does not appear to be a git repository’ error is to clone the remote repo using the ‘git clone’ command instead of initializing a repo with ‘git init’.

To do this;

  1. Run git clone https://github.com/username/repository-name.git, replacing username with your GitHub username and repository-name with the name of your repository or replacing the URL in the command with the URL of your repository.
  2. After making your changes to the repository, you can use the git add. command to add all changes or git add (file name/directory name) to add specific changes.
  3. Then use git commit –m “Commit message” to commit your changes, replacing Commit message with your desired commit message
  4. Finally, use git push to push your changes to the remote repo.

Fix 3: Change URL

If you incorrectly entered the URL to the remote repo or your GitHub fork of the repo, you would need to change the URL because entering it again might not work.

To do this, run git remote set-url origin https://github.com/user/correct-url, replacing the URL in the command with the correct URL of the GitHub repo or fork of the repo.

Fix 4: Change Origin

You can also try to change the origin to master when pulling the changes made to the master branch of your repo before adding the remote repo.

To do this, run git pull origin master to change the origin, then run the command above to change the URL if you have previously tried to add the remote repo. If you have not tried to add the remote repo at all, run git remote add origin https://github.com/user/remote-repo, replacing the URL in the command with the URL of your remote repository to add it. Then, run git push origin master to push your changes properly.

Fix 5: Remove and Add

To fix the ‘origin does not appear to be a git repository’ error, you can try checking the remotes set for the repo by running git remote –v. If this command gives no output, then no remote has been added (use the first fix above to add a remote origin). If the command displays the remotes set like this;

               Origin https://github.com/user/remote-repo (fetch)

               Orgin https://github.com/userr/remote-repo (push)

Check the URLs listed to confirm that they are correct. If they aren’t, use git remote remove origin to remove the wrong URL. In this case, we would replace origin with orgin seeing as the URL has a mistake and ‘orgin’ is a typo.

Then, run git remote, add origin: https://github.com/user/remote-repo with the correct URL and name, and run git push origin master to finish.

What Is A Git Repository?

A Git repository is a virtual version of your Git project that monitors and saves all the changes made in a directory called .git – this directory is what initializes a project folder as a Git project. A repository contains the various files and folders in a Git project folder. To work on a Git repository, you would need to import the files from the remote repository on github.com to your local server and local repository accessible from your computer using a terminal like Git Bash or command prompt.

The act of performing this import is known as ‘Cloning’. Once the remote repository is cloned to the local repository, you can easily access and edit the repo from your computer and then commit/push your changes to the remote repo on github.com. You can use GitHub repositories to build different projects using code and collaborate with other developers.

How To Get A Git Repository From Github

To get or clone an already existing remote repository from GitHub using a terminal like Git bash;

  1. Go to your account on github.com
  2. Locate the repository and open it, then click on Code above the list of files
  3. Note down the URL to clone with your desired method – click on HTTPS, SSH, or GitHub CLI to reveal the URL to clone with either
  4. With Git Bash downloaded and installed on your computer, open File Explorer and navigate to the folder or location where you want the cloned directory
  5. Right-click a free space in the folder and select Git Bash Here
  6. Run git clone https://github.com/username/repository-name.git, replacing username with your GitHub username and repository-name with the name of your repository or replacing the URL in the command with the URL of your repository.
  7. After making your changes to the repository, you can use the git add. command to add all changes or git add (file name/directory name) to add specific changes.
  8. Then use git commit –m “Commit message” to commit your changes, replacing Commit message with your desired commit message
  9. Finally, use git push to push your changes to the remote repo.

To get or clone an empty remote repository from GitHub using a terminal like Git bash;

  1. Go to your account on github.com
  2. Locate the repository and open it
  3. Then note down the URL for HTTPS or SSH under Quick Setup (you can also select Set up in Desktop and follow the prompts to set up the repo)
  4. With Git Bash downloaded and installed on your computer, open File Explorer and navigate to the folder or location where you want the cloned directory
  5. Right-click a free space in the folder and select Git Bash Here
  6. Run git clone https://github.com/username/repository-name.git, replacing username with your GitHub username and repository-name with the name of your repository or replacing the URL in the command with the URL of your repository.
  7. After making your changes to the repository, you can use the git add. command to add all changes or git add (file name/directory name) to add specific changes.
  8. Then use git commit –m “Commit message” to commit your changes, replacing Commit message with your desired commit message
  9. Finally, use git push to push your changes to the remote repo.

How To Create A Git Repository In Git

To create a local git repository and initialize it;

  1. Go to your account on github.com
  2. Click on the plus icon next to your photo at the top right corner of the screen and select New Repository
  3. Type in the repository name, scroll down, and tap Create repository
  4. Note down the URL of your new repository page
  5. With Git Bash downloaded and installed on your computer, open File Explorer and navigate to the folder or location where you want to create the Git repo
  6. Right-click a free space in the folder and select git Bash Here
  7. Run git init, then add a file to the folder using a text editor or the touch command, i.e., touch filename.txt
  8. Run git status to see if Git recognizes that you added a file
  9. Next, run git add. to add all your changes or git add filename.txt to add only the file
  10. Run git commit –m “Commit message” replacing Commit message with your desired commit message
  11. Then, run git remote add origin https://github.com/user/repository-name, replacing the URL in the command with the URL of your repository you noted down
  12. Finally, run git push –u origin master to push your codes to the remote repository

Conclusion

If you are stuck on the ‘origin does not appear to be a git repository’ error, this article has the solution and more. The problem could be something as simple as an incorrectly entered URL or a missing command. Read this to find out!