How to pull from official/master using github api for authenticated user?

Viewed 329

I have oauth2 access_token for user with scope repo which means I can basically access all public/private repos of the user. I have a local copy of a repo on my machine and I want to pull (fetch and merge) using the authenticated user's token in github api.
How do I manage this?

2 Answers

An OAuth access token, (like PAT (Personal Access Token)) can be used from command-line:

That OAuth token can be used as a password when GitHub asks for your credentials (username/password) for an HTTPS URL.

Therefore, make sure the remote URL is an HTTPS one, with <theuser> username in it

    cd /path/to/repo
    git remote -v
    # if origin starts with git@github.com (SSH)
    git remote set-url origin https://<theuser>@github.com/<theuser>/<repo>

Whenever you clone/pull/push a private repo from <theuser>, enter the OAuth access token as a password.

Or check your git config credential.helper: you can cache those credentials, using for instance the GCM (Git Credential Manager) like one for Mac/Linux, or for Windows.

Note that git merge is a local-only operation, so it won't require any credentials.

you can not do it locally, but I think it can be done as from docs

git pull is shorthand for git fetch followed by git merge FETCH_HEAD

you can achieve this by following the steps in order

  1. create branch
  2. create a new commmit
  3. update branch to point to new commit
  4. merge the new created branch with you want pull in
Related