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:
To check if you have setup an remote origin type
git remote -vcommand in your terminal.
The solution to this "no such remote origin" Git error is very simple, just follow the steps given below.
To initialize git, you have to type this command in your terminal:
To add the files to be tracked by Git, we use the command:
git add .
git add command adds the files or changes in your directory to the staging area.
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.
Next, we have to commit our local changes before pushing to remote using :
git commit -m "added new files"
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.
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.
-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.