Why git remote add is not working? - github

Why do I see an error message when typing git remote add?
$ git remote add origin remote repository https://github.com/hashanmalawana/Loginsystem.git
usage: git remote add [<options>] <name> <url>
-f, --fetch fetch the remote branches
--tags import all tags and associated objects when fetching
or do not fetch any tag at all (--no-tags)
-t, --track <branch> branch(es) to track
-m, --master <branch>
master branch
--mirror[=<push|fetch>]
set up remote as a mirror to push to or fetch from

You should type:
git remote add origin https://github.com/hashanmalawana/Loginsystem.git
not
git remote add origin remote repository https://github.com/hashanmalawana/Loginsystem.git
^^^^^^^^^^^^^^^^^^
That way, you add a remote named origin, referencing the remote repo https://github.com/hashanmalawana/Loginsystem.git
And you won't see the usage message
usage: git remote add [<options>] <name> <url>
I understand that the step 8 of "Adding an existing project to GitHub using the command line" can be confusing:
git remote add origin remote repository URL
But the last three parameters are actually only one. It should read:
git remote add origin <remote repository URL>
It is better to refer to the actual man page for git remote
git remote add <name> <url>

Related

What's wrong in git init ...?

When I use git init it only shows (master) and not (master -> origin), and then that when I use the command: git push -u origin master it returns an error:
error: src refspec master does not match any.
error: failed to push some refs to 'github.com:BghAek/something.git'
Most probably this happened:
Forget to add the remote repo link
You have created a new repository using the init command, but it looks like you forgot to add the link to the remote repository. So do the following:
Remove the `.git` file from you local system.
Create a clean repository using the following:
git init
git add .
git commit -m "COMMIT MESSAGE"
git branch -M main
git remote add origin REMOTE_REPOSITORY_LINK
git push -u origin main
replace REMOTE_REPOSITORY_LINK with that of the remote repository link. Remember your are on main branch, so as to keep it consistent with the remote branch( read more here).

How to setup github login to push file using cmd

I have setup my github using the global command, but when I try to push my file it request this commands:
git remote add <name> <url> and then push using the remote name git push <name>
When I carefully follow the command it requests for this command:
To push the current branch and set the remote as upstream, use git push --set-upstream gh-pages master
I typed in the command, then I was asked for username which I typed now the next input which is the password, the command line failed to effect the insertion point.

How to resolve "fatal: unable to access " error

I'm a beginner to GitHub.I need to send a pull request to the master branch.
when i typed the code
git push origin master
It gives me the error
fatal: unable to access
'https://github.com/www-prolificme-com/mahawiki/': The requested URL
returned error: 403
Updated
You mentioned you are trying to pull from git but the command is git push. Anyways, most probably you are getting this error because your repo url is not set locally.
If this is the first time you are sending git request from your system, you might want to setup your username by git config --global user.name "John Doe"
If you have already used git on your system, try checking the git configuration on your system using git config --list command to check whether your repo URL is setup or not.
If the url is not setup run git remote set-url origin https://github.com/www-prolificme-com/mahawiki/
Run git remote -v to verify if your url is setup
git add .
git commit -m "your message"
git push origin master
Remove/Update the saved credentials:
Click Start
Search for 'Credential Manager'
Select 'Windows Credentials Manager' > 'Windows Credentials'
Search for the credentials that you want to remove/update
Click on the credential entry > Click 'Edit' or 'Remove'
your repo is not setting locally
so, you seemed crash message
first
git config --list
to showing your git repo set list
and
git remote set-url origin <your git repo address>
to access git repo and git add . to add your files to git container
git commit -m "your git commit message"
this is your git commit message version or anything possible
git push origin master
finally your files pushing on git repo
it's done!
try it
I got this same problem then I try to this below command.
step 1:
git config --global user.email "user email"
step 2:
git config --global user.name "user name"
After running those commands, you can use this command to push your code:
git push origin master
Even if you set all credentials and other setups in the local machine, you might face this problem.
Currently, GitHub uses 'personal access token' so when or after creating personal access token you must check the Select scopes.
You select all you need and then push again.
It will be pushed successfully.
If nothing working please check if you have checked the below checkboxes while creating token

How do I add my repos to another persons repo?

I have a microservices application, so the front-end on the first repo and two different backend APIs on two different repos. I want to add all these to someone else's empty repo and I am not sure how to do this.
I tried doing a git remote add of the other persons repo and I get this:
danales-MacBook-Pro:freelance-camp-fe danale$ git remote add https://github.com/Meridian-Business-Centers/Interview-Sample-App.git
usage: git remote add [<options>] <name> <url>
-f, --fetch fetch the remote branches
--tags import all tags and associated objects when fetching
or do not fetch any tag at all (--no-tags)
-t, --track <branch> branch(es) to track
-m, --master <branch>
master branch
--mirror[=<push|fetch>]
set up remote as a mirror to push to or fetch from
When I do a git remote add microservice master I get this error:
danales-MacBook-Pro:freelance-camp-fe danale$ git push microservice master
remote: Permission to Meridian-Business-Centers/Interview-Sample-App.git denied to ldco2016.
fatal: unable to access 'https://github.com/Meridian-Business-Centers/Interview-Sample-App.git/': The requested URL returned error: 403
I tried pushing it to my own forked version and got this error:
danales-MacBook-Pro:freelance-camp-fe danale$ git remote add microservice https://github.com/ldco2016/Interview-Sample-App.git
fatal: remote microservice already exists.
danales-MacBook-Pro:freelance-camp-fe danale$ git push microservice master
To https://github.com/ldco2016/Interview-Sample-App.git
! [rejected] master -> master (fetch first)
error: failed to push some refs to 'https://github.com/ldco2016/Interview-Sample-App.git'
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first integrate the remote changes
hint: (e.g., 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
danales-MacBook-Pro:freelance-camp-fe danale$ git push -u microservice master
To https://github.com/ldco2016/Interview-Sample-App.git
! [rejected] master -> master (fetch first)
error: failed to push some refs to 'https://github.com/ldco2016/Interview-Sample-App.git'
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first integrate the remote changes
hint: (e.g., 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
Go into every separate repo and add a remote (say, personal) with the url of other persons empty github repo. Now push the code like git push personal master.
Say, you have repo1, repo2 and repo3. And a personal repo perRepo (want to add repo1, repo2 and repo3 codes here).
# Go into repo1
$ git checkout master
$ git remote add personal <perRepo-url>
$ git push personal master
# Go into repo2
$ git checkout master
$ git remote add personal <perRepo-url>
$ git push personal master
# Go into repo3
$ git checkout master
$ git remote add personal <perRepo-url>
$ git push personal master
Add Submodule: General command: git submodule add <git#XXX:YYY> <externals>.
git submodule add: Simply tells Git we are adding a submodule
git#XXX:YYY: External repository URL that is to be added as a submodule
externals: This is the path where the submodule repository will be added to the main repository.
More Submodule
Add repo1, repo2 and repo3 as submodule of perRepo.
# Go into perRepo
$ git submodule add <repo1-url> <path>
$ git submodule add <repo2-url> <path>
$ git submodule add <repo3-url> <path>
$ git submodule update --init --recursive
N.B. when repo1/repo2/repo3 would be updated you need to run git submodule update command to get the updated changes into perRepo repo.

Github- repository is on remote but not found when pushing

I'm trying to push something to github and I'm getting this error;
Robbies-MacBook-Pro:assn-6-huffman-mac user$ git push -u origin master
fatal: repository 'https://github.com/BitMechanic/Stanford-CS106b/Huffman.git/' not found
Then when I check I get this;
Robbies-MacBook-Pro:assn-6-huffman-mac user$ git remote add origin https://github.com/BitMechanic/Stanford-CS106b/Huffman
fatal: remote origin already exists.
Robbies-MacBook-Pro:assn-6-huffman-mac user$ git remote -v
origin https://github.com/BitMechanic/Stanford-CS106b/Huffman.git
(fetch)
origin https://github.com/BitMechanic/Stanford-CS106b/Huffman.git
(push)
Anyone know what I'm doing wrong?
The proper url to use (for cloning and then pushing through origin) is
https://github.com/BitMechanic/Stanford-CS106b.git
not:
https://github.com/BitMechanic/Stanford-CS106b/Huffman.git
Stanford-CS106b is a repo, listed in the BitMechanic's repo page of d. Stanford-CS106b/Huffman is not.
To fix this, see git remote commands:
git remote rm origin
git remote add origin https://github.com/BitMechanic/Stanford-CS106b.git
or, simpler:
git remote set-url origin https://github.com/BitMechanic/Stanford-CS106b.git
Can you paste the
$cat .git/config
output here for reference.
Sometimes it is better to remove the remotes that are misbehaving from there and re-add it using the git remote add command again.