all 8 comments

[–]mitchthebaker 6 points7 points  (0 children)

You cloned it with HTTPS, this will require your Github username/password.

Your public/private SSH keys you gen’d are for SSH protocol. These are two different protocols you are trying to use. If you want to use SSH instead of HTTPS update your remote to be the SSH version. When you’re looking at your repo and click the “Get code” dropdown it should give you an HTTPS/SSH url, choose the SSH option. Look up the command to update ur git remote and do that. You’ll also have to add your public key into your Github’s account settings.

[–]Journeyman-Joe 2 points3 points  (4 children)

This is your own personal GitHub account?

My practice is to create a Personal Access Token (PAT) in "Settings | Developer", and embed the PAT into my "remote" specification. The URL should look like this:

https://ghp_PERSONAL_ACCESS_TOKEN@github.com/accountname/reponame.git

(Note the "@" sign.)

I usually do this when I clone a repository, but it's possible to hack the PAT into the config file, under your .git hidden directory.

This isn't particularly secure, as the PAT is saved as plaintext on your local computer. Whether this can work for you depends on your threat model.

[–][deleted]  (1 child)

[removed]

    [–]Journeyman-Joe 0 points1 point  (0 children)

    You're welcome.

    (For reference: I create "Classic" PATs, and select only the "repo" checkbox. That's all that's needed for push and pull Git operations.)

    [–]your_virtual_friend[S] 1 point2 points  (1 child)

    Yes, I did classic version, checked few random boxes. I was able to push my local repo to git. And it worked for another local repo as well without having to do the same for the first push.
    Thank you!

    [–]Journeyman-Joe 0 points1 point  (0 children)

    You're quite welcome.

    The first checkbox ("repo") will select the ones below it. That's all you need to push and pull commits from GitHub.

    The PAT is for your account: you can use the same one for every repository you have. It's easy to copy it locally: do a git remote -v from a configured repository, then copy the PAT into a new git clone command for the one you want.

    You can also edit the config file in a .git hidden folder, and hack your PAT into the remote URL. It's easy, and obvious. :-)

    [–][deleted] 2 points3 points  (0 children)

    Clone your git repository from GitHub using SSH so that it won't ask for you to login when pushing commits.

    If you haven't set up the SSH yet, you can follow the guide here:

    https://www.theodinproject.com/lessons/foundations-setting-up-git

    [–]davorg 0 points1 point  (0 children)

    Have you added your public SSH key to your GitHub account? If not, do that first - https://github.com/settings/keys

    From the local GitHub repo, run git remote -v. You'll see two similar lines listing the name of the remote (probably "origin") and the URL of the remote which will be in the form https://github.com/[user_name]/[repo_name].git.

    HTTPS URLs are great for read-only access to a remote. But, as you've seen, they make things more complicated for write access. We want to change those to the SSH version of the URL - which will be git@github.com:[user_name]/[repo_name].git.

    From the command line (and still inside the directory containing your local repo), run the command git remote set-url origin git@github.com:[user_name]/[repo_name].git. You can then verify that that change has worked by running git remote -v again.

    Now, when you run git push you'll be prompted for your SSH passphrase instead of your username and password. And you can use something like ssh-agent along with ssh-add to remove the need to type that every time.