Git - Add remote to existing repository

I am unable to do following step:

# Add remote to existing repository
You can add remote using git remote add origin git@github.com:<username>/<repo-name>.git command.

[ankitapurohit24408@cxln5 ~]$ git remote add origin git@github.com:/.git
-bash: Ankita-Purohit: No such file or directory

Please note that the username and repo name is correct.

Please advise what needs to be done.
Thanks!

Hi @Ankita_Purohit ,

To use this command you have to first configure ssh keys if you didn’t please use the below command instead.
git remote add origin https://github.com/<your-github-username>/<your-repo-name>.git

I took following steps:

  • git init
  • git remote add origin https://github.com//.git
  • ssh-keygen -t rsa -b 4096
  • created my passphrase, got the key as output and pasted that key on Git/settings/SSH key
  • made changes to my local helloworld.py
  • brought that file to the staging area–> git add helloworld.py
  • committed it–> git commit -m “Adding: updating the file so that I can push it to git hub repo.” helloworld.py
  • git pull branch master
  • git push -u origin master

[ankitapurohit24408@cxln5 ~]$ git push -u origin master
Username for ‘https://github.com’: Ankita-Purohit
Password for ‘https://Ankita-Purohit@github.com’:
Branch master set up to track remote branch master from origin.
Everything up-to-date
Does it mean that master is pushed?
But while submiting on slide 12/13 on Git Hands-on I get this message: The master branch is not pushed on remote repository.

Thanks for your help Sachin.

Hi @Ankita_Purohit,
The directory name should be ‘devops’.

Yes I tried all the commands again while in devops. Please see below:

[ankitapurohit24408@cxln5 ~]$ cd devops
[ankitapurohit24408@cxln5 devops]$ git status

On branch master

nothing to commit, working directory clean
[ankitapurohit24408@cxln5 devops]$ echo ‘print(“Adding new line to it”)’ >> helloworld.py
[ankitapurohit24408@cxln5 devops]$ cat helloworld.py
print(“Hello World”)
print(“I am learning git”)
print(“Adding: updating the file so that I can push it to git hub repo.”)
print(“Adding another line to it”)
print(“Adding another line to it”)
print(“Adding new line to it”)
[ankitapurohit24408@cxln5 devops]$ git add helloworld.py
[ankitapurohit24408@cxln5 devops]$ git status

On branch master

Changes to be committed:

(use “git reset HEAD …” to unstage)

modified: helloworld.py

[ankitapurohit24408@cxln5 devops]$ git commit -m “Trying to push3” helloworld.py
[master c60923a] Trying to push3
1 file changed, 1 insertion(+)
[ankitapurohit24408@cxln5 devops]$ git push -u origin master
fatal: ‘origin’ does not appear to be a git repository
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
[ankitapurohit24408@cxln5 devops]$ git pull branch master
fatal: ‘branch’ does not appear to be a git repository
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.
[ankitapurohit24408@cxln5 devops]$ git push -u origin master
fatal: ‘origin’ does not appear to be a git repository
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.

Please advise.
Thanks.

Hi @Ankita_Purohit,
Please add remote using
git remote add origin https://github.com/<your-github-username>/<your-repo-name>.git .

It’s done now.

Thanks Sachin.

1 Like