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;
- Go to github.com and sign in to your account
- Locate the repo you want to clone and click on it to open
- Then, note down the URL of the page
- Run git remote add origin , replacing the URL in the command with the URL of the remote repository you noted down
- You can also replace user and remote-repo in the URL above with your username and repository name, respectively
- 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;
- Run git clone , 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.
- 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.
- Then use git commit –m “Commit message” to commit your changes, replacing Commit message with your desired commit message
- 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 , 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 , 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 (fetch)
Orgin (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: 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;
- Go to your account on github.com
- Locate the repository and open it, then click on Code above the list of files
- 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
- 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
- Right-click a free space in the folder and select Git Bash Here
- Run git clone , 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.
- 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.
- Then use git commit –m “Commit message” to commit your changes, replacing Commit message with your desired commit message
- 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;
- Go to your account on github.com
- Locate the repository and open it
- 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)
- 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
- Right-click a free space in the folder and select Git Bash Here
- Run git clone , 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.
- 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.
- Then use git commit –m “Commit message” to commit your changes, replacing Commit message with your desired commit message
- 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;
- Go to your account on github.com
- Click on the plus icon next to your photo at the top right corner of the screen and select New Repository
- Type in the repository name, scroll down, and tap Create repository
- Note down the URL of your new repository page
- 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
- Right-click a free space in the folder and select git Bash Here
- Run git init, then add a file to the folder using a text editor or the touch command, i.e., touch filename.txt
- Run git status to see if Git recognizes that you added a file
- Next, run git add. to add all your changes or git add filename.txt to add only the file
- Run git commit –m “Commit message” replacing Commit message with your desired commit message
- Then, run git remote add origin , replacing the URL in the command with the URL of your repository you noted down
- 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!
- Chrome Localhost Refused To Connect on Windows 10? Working Fixes
- Nvidia GeForce Experience Not Working error code 0x0003 – Best Fixes
- Assistantd Wants to Use the Login Keychain – Best Fixes
- Commcenter Wants to Use the Login Keychain – Best Fixes
A tech writer with a passion for demystifying complex technology for the masses. With a background in computer science and a knack for clear and concise communication, I have made a name for myself in the tech industry as a go-to source for understandable and engaging explanations of the latest developments. Learn more about tekpip and the team here on our about us page.