Find out how to solve the git no such remote origin error while working with the Git repository.

Sometimes when we try to push our local changes to our remote repository we might come across an error : "no such remote origin" when we try to push the changes to a remote repo.

This error might occur for two reasons:

  1. You haven't told Git to start tracking any file, or
  2. You have not set up the remote origin in your local repsitory.

To check if you have setup an remote origin type git remote -v command in your terminal.

The solution to this "no such remote origin" Git error is very simple, just follow the steps given below.

Step 1: Intialize Git in your working folder

To initialize git, you have to type this command in your terminal:

git init

Step 2: Add the files to track by Git

To add the files to be tracked by Git, we use the command:

git add .

The git add command adds the files or changes in your directory to the staging area.

The git add . , adds all the new files and changes to the staging area.

Or if you want to add only a specify file to be push to remote, type:

git add filename.md

Note: Add the file name with the extension.

Step 3: Commit our local changes

Next, we have to commit our local changes before pushing to remote using :

git commit -m "added new files"

Step 4: Set up Git remote origin

Here, we will add the remote git repository to our local repository using the command git remote add origin with the git repository URL.

git remote add origin https://github.com/USERNAME/RepoName.git

This will now let the local repository to communicate with the remote repository on Github to commit our changes or pull new changes from the remote one.

Note: To get the github repository URL, make sure you have already created a repo in Github.

Step 5: Push the changes to remote repository

The last step would be to push all the changes from our local repo to the remote repository using the command:

git push -u origin master

This will push all the changes to the master branch.

The -u flag adds a tracking reference for every branch you have successfully push onto the remote repository. So next time you can just use the git pull without any arguments and Git will know from which branch to pull the remote changes from.

Conclusion: If you follow the above steps properly then you can avoid the "no such remote origin" error in Git.


Related Topics:

How to change URL of Git remote origin


💾 Recommended Articles