add instructions to switch from https to ssh in ssh-key.md

This commit is contained in:
narF 2022-10-24 02:19:30 +02:00 committed by Gitea
parent b0b19675f2
commit 7fba31ab1d

View file

@ -116,5 +116,50 @@ $ eval $(ssh-agent)
$ ssh-add # enter your passphrase once, then it is cached.
```
## Changing your repository from HTTPS to SSH
1. Go to the directory where your repository is located:
```
cd /path/to/repository
```
2. Look at the existing remotes with `git remote` :
```
git remote -v
```
It will look similar to this:
```
origin https://codeberg.org/knut/foobar.git (fetch)
origin https://codeberg.org/knut/foobar.git (push)
```
You might be using a different name than `origin` for your repository. If you do, remember to use that different name in the following steps.
3. Run `git remote set-url` command followed by the remote name and the remotes URL:
```
git remote set-url <remote-name> <remote-url>
```
For example, to change the URL of `origin` to `git@codeberg.org:knut/foobar.git` you would type:
```
git remote set-url origin git@codeberg.org:knut/foobar.git
```
4. Verify that your change was successful:
```
git remote -v
```
The output should look like this:
```
origin ssh://git@codeberg.org:knut/foobar.git (fetch)
origin ssh://git@codeberg.org:knut/foobar.git (push)
```
> **Attribution**
> This guide is derived from [GitHub Docs](https://docs.github.com), used under CC-BY 4.0.