document using token to clone private repo #458

Open
opened 2024-07-29 00:12:16 +02:00 by soas · 4 comments

Hello!!! I just solved a problem that has been bugging me for years.

If you have a private repo, how do you clone it?? Especially when multiple accounts, keys and other credentials are in the mix. (I know that in theory there are ways and I've even done it once or twice, but they are quite fragile and/or forgetable.)

Codeberg Docs Generating an Access Token tells you how to make an access token but then you are on your own. Put it in your mobile app or something. I read it a long time ago and never thought much more of it. I am very Basic user; totally amateur hour over here.

I read on SOF this comment about how to do this for github:

We should have or create personal access token. You can refer creating a personal access token link to create one. And the command should be:
git clone https://<personal_access_token>@github.com/<your account or organization>/<repo>.git

And also this longer one with screenshots of how GitHub does it. This one made me wonder if it is possible with codeberg, and it is!

Tried making an oauth2 token but couldn't figure that out so used the regular "access token" and it seems to work with line like

git clone https://oauth2:tokentokentokentokentokentoken@codeberg.org/user/repo

This should be documented because it is very useful.

  • Would be really nice: link to the documentation from the place a person might look for it, ex

    • in Settings where you make the repo private
  • in this zone:
    image

  • I have some vague sense there might be something required after this to make it into an ssh authenticated situation afterwards? I recall from previous attempts at solving this issue. git-config?

Sorry this isn't extremely well composed. If it is unintelligible let me know and I will tighten it up.

There are likely some nuts n bolt details/complications of which I am ignorant, hopefully someone more knowledgeable can bring them up.

Hello!!! I just solved a problem that has been bugging me for years. If you have a private repo, how do you clone it?? Especially when multiple accounts, keys and other credentials are in the mix. (I know that in theory there are ways and I've even done it once or twice, but they are quite fragile and/or forgetable.) Codeberg Docs [Generating an Access Token](https://docs.codeberg.org/advanced/access-token) tells you how to make an access token but then you are on your own. Put it in your mobile app or something. I read it a long time ago and never thought much more of it. I am very Basic user; totally amateur hour over here. I read on SOF [this comment](https://stackoverflow.com/a/75721352) about how to do this for github: > We should have or create personal access token. You can [refer creating a personal access token link](https://docs.github.com/en/enterprise-server@3.4/authentication/keeping-your-account-and-data-secure/creating-a-personal-access-token) to create one. And the command should be: > `git clone https://<personal_access_token>@github.com/<your account or organization>/<repo>.git` And also [this longer one with screenshots](https://stackoverflow.com/a/74890752) of how GitHub does it. This one made me wonder if it is possible with codeberg, and it is! Tried making an oauth2 token but couldn't figure that out so used the regular "access token" and it seems to work with line like ```sh git clone https://oauth2:tokentokentokentokentokentoken@codeberg.org/user/repo ``` This should be documented because it is very useful. - Would be really nice: link to the documentation from the place a person might look for it, ex - in Settings where you make the repo private - in this zone: <img width="690" alt="image" src="/attachments/761ff8a9-a4c9-4093-a4ee-668d4c832c44"> - I have some vague sense there might be something required after this to make it into an ssh authenticated situation afterwards? I recall from previous attempts at solving this issue. git-config? Sorry this isn't extremely well composed. If it is unintelligible let me know and I will tighten it up. There are likely some nuts n bolt details/complications of which I am ignorant, hopefully someone more knowledgeable can bring them up.
Author

Hi thanks for doing that!

I don't know if this should be done here, or there. Or maybe make a PR? If it's not too elaborate to set up locally I might be able to do that but not sure if I would be waiting for this change to be completed, or making it against the proposed commit, or what. So if it's simpler to just take from this whatever is useful probably better.

This is suggestions to make things extremely explicit. But it destroys the terseness so idk might not be appreciated. It depends who is your target audience really.

This is the exact version I am looking at, in case it changes in the future: 9f7d0bad4a/content/git/clone-commit-via-cli.md

Suggest to add somewhere:

You don't need to do anything in the "OAuth2" section of the page.

  • because the instructions later involve a line mentioning oauth2

Suggesting changing:

You only need to scope the access token to have read/write access to repositories for this operation.

to something less technical. Assuming I understood the instructions correctly would be like:

  • Open the "Select permissions" drop down
  • under "repository", select the drop down "read and write"
  • leave all other drop down menus unchanged unless you have a specific reason

Suggest adding how to convert to SSH; something like:

Now you have the private repo cloned, but it is authenticated with HTTPS which has some implications

  • if you want to push any changes you will have to type a password each time

  • if you delete the access token from your account, you can no longer pull changes from the remote

So you should change your local repo to use SSH authentication instead.

You will first need to have SSH keys set up and the key available in your local environment. Refer to Adding an SSH key to your account.

In the terminal, cd into the repo directory. Assuming your remote name is origin, issue the following command

git remote set-url origin git@codeberg.org:user/repo.git

For more detailed instructions, please refer to Changing your repository's transport from HTTPS to SSH

Hi thanks for doing that! I don't know if this should be done here, or there. Or maybe make a PR? If it's not too elaborate to set up locally I might be able to do that but not sure if I would be waiting for this change to be completed, or making it against the proposed commit, or what. So if it's simpler to just take from this whatever is useful probably better. This is suggestions to make things extremely explicit. But it destroys the terseness so idk might not be appreciated. It depends who is your target audience really. This is the exact version I am looking at, in case it changes in the future: https://codeberg.org/Codeberg/Documentation/src/commit/9f7d0bad4a207ed27c1ee0c0ffbb70260fae6faf/content/git/clone-commit-via-cli.md Suggest to add somewhere: > You don't need to do anything in the "OAuth2" section of the page. - because the instructions later involve a line mentioning oauth2 Suggesting changing: > You only need to scope the access token to have read/write access to repositories for this operation. to something less technical. Assuming I understood the instructions correctly would be like: > - Open the "Select permissions" drop down > - under "repository", select the drop down "**read and write**" > - leave all other drop down menus unchanged unless you have a specific reason Suggest adding how to convert to SSH; something like: > Now you have the private repo cloned, but it is authenticated with HTTPS which has some implications > > - if you want to push any changes you will have to type a password each time > > - if you delete the access token from your account, you can no longer pull changes from the remote > > So you should change your local repo to use SSH authentication instead. > > You will first need to have SSH keys set up and the key available in your local environment. Refer to [Adding an SSH key to your account](https://docs.codeberg.org/security/ssh-key/). > > In the terminal, `cd` into the repo directory. Assuming your remote name is `origin`, issue the following command > > ```sh > git remote set-url origin git@codeberg.org:user/repo.git > ``` > > For more detailed instructions, please refer to [Changing your repository's transport from HTTPS to SSH](https://docs.codeberg.org/security/ssh-key/#changing-your-repository's-transport-from-https-to-ssh)
Author

Looks like this got lost. :( I see at https://codeberg.org/Codeberg/Documentation/src/branch/main/content/git/clone-commit-via-cli.md it is not included.

I am always referring back to this thread to remember how to do it.

Works for me but kind of hard to find for others.

Looks like this got lost. :( I see at https://codeberg.org/Codeberg/Documentation/src/branch/main/content/git/clone-commit-via-cli.md it is not included. I am always referring back to this thread to remember how to do it. Works for me but kind of hard to find for others.

@soas thank you

@soas thank you
Author

Hey everyone! is there anything kinda basic that I can do to get this included?

I can't follow what happened in #459 though.... That's over my head. If the blockage has to do with a zillion merge conflicts from months ago I don't know what to do about solving that.

I refer to this thread almost every time I work on my stuff, it's so useful. Maybe I have some unusual work style and the info is not of general interest?

Hey everyone! is there anything kinda basic that I can do to get this included? I can't follow what happened in https://codeberg.org/Codeberg/Documentation/pulls/459 though.... That's over my head. If the blockage has to do with a zillion merge conflicts from months ago I don't know what to do about solving that. I refer to this thread almost every time I work on my stuff, it's so useful. Maybe I have some unusual work style and the info is not of general interest?
Sign in to join this conversation.
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Codeberg/Documentation#458
No description provided.