nus-cs2113-AY2223S2 / forum

10 stars 0 forks source link

How to get a Personal Access Token to use as password for SourcetreešŸ’” #8

Open SongZijin opened 1 year ago

SongZijin commented 1 year ago

I faced some trouble when trying to push my commits, I got some help from Prof and hope this can help more people.

When setting up the account, use [Auth Type: Basic] and your GitHub username. For the password, instead of using your GitHub password, you would need to create a Personal Access Token on GitHub, through the following steps:

  1. Go to settings in GitHub
  2. Scroll all the way down to [Developer Settings] on the left sidebar
  3. Select [Personal Access Tokens], then [Tokens (classic)]
  4. Select [Generate new token (classic)] under [Generate new token]
  5. Tick the appropriate fields as the PDF attached
  6. Remember to change the expiry time to after the semester and name the token
  7. After clicking [Generate token], you will see a String with a prompt to copy it, you can use that as the password for your account Be sure to save this String and not show it to anyone else! After setting up this account, the push of commits should work as desired. New Personal Access Token (Classic).pdf
joulev commented 1 year ago

My two cents:

okkhoy commented 1 year ago

@joulev

For "Generate new token (classic)", you only need to check the "repo" box at the top to get push access. No need of "workflow" and so on.

No need of "workflow" and so on. Sure this works?

However, I recommend authenticating with SSH instead, no more pasting the token every time you need to make a push. It shouldn't take more than a few minutes to set this up (just copy all the commands in the linked page, really, and paste them to the terminal).

I am all for SSH authentication. However, the second part shouldn't be the case (i.e., pasting each push). The credential manager should take care of the PAT. However, I am not sure about the implications (read security) of using the credential manager.

joulev commented 1 year ago

@joulev

For "Generate new token (classic)", you only need to check the "repo" box at the top to get push access. No need of "workflow" and so on.

No need of "workflow" and so on. Sure this works?

I haven't generated a token for a long time so I am not 100% sure, but I'm like 95% sure that the "workflow" option is for interacting with GitHub Actions and similar, and is not required for push access.

To be absolutely sure, it's best to consult the documentation at https://docs.github.com but as I'm on mobile right now... sorry I can't link the specific page here.

okkhoy commented 1 year ago

Please check and confirm, if you can, for the benefit of the class.

joulev commented 1 year ago

I just checked the documentation and as written in here,

For workflow this sentence is interesting:

Workflow files can be committed without [workflow] if the same file (with both the same path and contents) exists on another branch in the same repository.

Once again, I really recommend everyone to spend 10 minutes setting up SSH so that you don't have to deal with all this mess.

okkhoy commented 1 year ago

Thanks! I suppose in my case, since I handle repositories in another module that involves CI, it requires me to setup all these permissions (though I dun remember when I set it up).

joulev commented 1 year ago

Thanks! I suppose in my case, since I handle repositories in another module that involves CI, it requires me to setup all these permissions (though I dun remember when I set it up).

I think from the sentence in the documentation, if you need to create a new workflow or delete a workflow (.github/workflows/*.yml), you need the workflow permission. But if you create or delete the file using the GitHub UI (on github dot com) for example, you can then edit the workflows locally without the workflow permission.

Later on if we will use GitHub Actions for continuous integration, then it is indeed necessary to use workflow to avoid weird errors that GitHub will give.