Home > Mobile >  How do I simply upload a local directory to git
How do I simply upload a local directory to git

Time:08-27

UPDATE: I am now informed that github no longer accepts connections using https://github.com/username/repoName, and instead am now using ssh -T [email protected] to connect after following the instructions on setting up SSH with github here:

I cannot make head nor tail of github's own instructions on how to upload a repository on my local computer to git.

I have tried

 git remote add myDir https://github.com/myGitHubUsername/myAlreadyExistingRepo

but I get 'Could not read from remote repository'

I have used the url given in github for the repo (https://github.com/myGitHubUsername/myAlreadyExistingRepo) so I don't understand why it won't work. All the articles I can find on google etc require me to follow this first step, but it doesn't sem to function properly.

I am running the command from inside a directory which I have initialized in git. Could it be a problem with the connection?

CodePudding user response:

So I registered my SSH public key with github, and got the authenticated message

But you still need to switch to SSH for your local repository URL.
(For HTTPS, see your next question)

cd /path/to/local/repository
git remote set-url myDir [email protected]:myGitHubUsername/myAlreadyExistingRepo
git remote -v
git push -u myDir main

Note: generally, one would change origin instead of myDir: origin is the default remote name used by Git.

Then and only then Git would try and user your $HOME/.ssh/id_rsa default SSH key (or %USERPROFILE%\.ssh\id_rsa on Windows).

CodePudding user response:

Here is the good pratice, when you try to push an existing repository to github remote existed repo.

git remote add origin https://github.com/path/to/your/repo.git
git branch -M main
git push -u origin main

I think origin is not replaced as myDir.

BTW, password authentication is abandond by Github.

remote: Support for password authentication was removed on August 13, 2021.
remote: Please see https://docs.github.com/en/get-started/getting-started-with-git/about-remote-repositories#cloning-with-https-urls for information on currently recommended modes of authentication.
  • Related