diff --git a/content/_includes/redirect.njk b/content/_includes/redirect.njk new file mode 100644 index 0000000..2e56cdc --- /dev/null +++ b/content/_includes/redirect.njk @@ -0,0 +1,10 @@ + + +
+ + + + + Redirecting to {{ redirect.to }} + + diff --git a/content/git/clone-commit-via-http.md b/content/git/clone-commit-via-cli.md similarity index 56% rename from content/git/clone-commit-via-http.md rename to content/git/clone-commit-via-cli.md index 46485d3..d84d6b9 100644 --- a/content/git/clone-commit-via-http.md +++ b/content/git/clone-commit-via-cli.md @@ -1,53 +1,82 @@ --- eleventyNavigation: - key: CloneCommitViaHTTP - title: Clone & Commit via HTTP + key: CloneCommitviaCLI + title: Clone & Commit via CLI parent: Git order: 20 --- -Clone, edit, commit, push and pull can be performed using Git directly from the command line, by using a Git client, or via the web interface. The first option is shown below and in the section [Clone & Commit via SSH](/git/clone-commit-via-ssh). The last option is detailed in the section [Clone & Commit via Web](/git/clone-commit-via-web). +Clone, edit, commit, push and pull can be performed using Git directly from the command line, by using a Git client, or via the web interface. The former option is shown below. The latter option is detailed in the section [Clone & Commit via Web](/git/clone-commit-via-web). -The user in these examples is `knut` the polar bear and its repository is `foobar`. The repository was created via the Codeberg website including a `README.md` file. +The user in these examples is `knut` the polar bear and its repository is `examples`. The repository was created via the Codeberg website, including a `README.md` file. ## Clone *Cloning* refers to the process of creating an identical copy of a repository to the local machine. Clone with the Git command `clone` followed by the repo URL. -```bash -~$ git clone https://codeberg.org/knut/foobar.git -Cloning into 'foobar'... +### HTTP +```shell +~$ git clone https://codeberg.org/knut/examples.git +Cloning into 'examples'... remote: Enumerating objects: 3, done. remote: Counting objects: 100% (3/3), done. remote: Total 3 (delta 0), reused 0 (delta 0) Unpacking objects: 100% (3/3), 214 bytes | 1024 bytes/s, done. ``` +### SSH +Before you are able to access Git repositories via SSH, you need to [add an SSH key to your account](/security/ssh-key). + +> **Warning** +> Please make sure that before connecting to Codeberg via SSH, +> you have [verified Codeberg's SSH fingerprint](/security/ssh-fingerprint)! + +If you have set up a passphrase, you will be asked for it. + +```shell +~$ git clone git@codeberg.org:knut/examples.git +Enter passphrase for key '/home/knut/.ssh/id_rsa': **** +Cloning into 'examples'... +remote: Enumerating objects: 3, done. +remote: Counting objects: 100% (3/3), done. +remote: Compressing objects: 100% (2/2), done. +remote: Total 3 (delta 0), reused 0 (delta 0) +Unpacking objects: 100% (3/3), done. +``` + ## Edit Modify an existing file: -```bash +```shell ~$ cd foobar -~/foobar$ vim README.md +~/examples$ nano README.md ``` +Here we use `nano`, but you can use any (text) editor you want. + ## Commit A *commit* is a record of the changes to the repository. This is like a snapshot of your edits. A commit requires a commit message. For the example below, the message is "test". Keep in mind that "test" is not a very informative message, though. In the real world, make sure your commit message is informative, for you, your collaborators and anyone who might be interested in your work. Some advice on how to write a good commit message can be found on countless websites and blogs! Command lines: -```bash -~/foobar$ git commit -am 'test' +```shell +~/examples$ git commit -am 'test' [master 10074d7] test 1 file changed, 2 insertions(+), 1 deletion(-) ``` +Here's an explanation of the command flags used here: +- `-a`: automatically stages modified and deleted files for commits. +- `-m`: commit message + ## Push The last step is to synchronize (*push*) the modifications (commit) from the local repository to the remote one on Codeberg. -```bash -~/foobar$ git push https://codeberg.org/knut/foobar.git +If you are using HTTP, you will be asked for your Codeberg username and password. + +```shell +~/examples$ git push Username for 'https://codeberg.org': knut Password for 'https://knut@codeberg.org': Counting objects: 3, done. @@ -55,7 +84,7 @@ Delta compression using up to 4 threads. Compressing objects: 100% (2/2), done. Writing objects: 100% (3/3), 266 bytes | 0 bytes/s, done. Total 3 (delta 1), reused 0 (delta 0) -To https://codeberg.org/knut/foobar.git +To https://codeberg.org/knut/examples.git 662e04e..10074d7 master -> master ``` diff --git a/content/git/clone-commit-via-ssh.md b/content/git/clone-commit-via-ssh.md deleted file mode 100644 index 0b756e3..0000000 --- a/content/git/clone-commit-via-ssh.md +++ /dev/null @@ -1,56 +0,0 @@ ---- -eleventyNavigation: - key: CloneCommitViaSSH - title: Clone & Commit via SSH - parent: Git - order: 40 ---- - -Before you are able to access Git repositories via SSH you need to [add an SSH key to your account](/security/ssh-key). - -> **Warning** -> Please make sure that before connecting to Codeberg via SSH, -> you have [verified Codeberg's SSH fingerprint](/security/ssh-fingerprint)! - -The user in these examples is `knut` and its repository is `examples`. The repository was created via the Codeberg.org website including a `README.md` file. - -## Clone the repo -```bash -~$ git clone git@codeberg.org:knut/examples.git -Enter passphrase for key '/home/knut/.ssh/id_rsa': **** -Cloning into 'examples'... -remote: Enumerating objects: 3, done. -remote: Counting objects: 100% (3/3), done. -remote: Compressing objects: 100% (2/2), done. -remote: Total 3 (delta 0), reused 0 (delta 0) -Unpacking objects: 100% (3/3), done. -``` - -## Modify and commit to local repository -Modify an existing file - -```bash -~$ cd example -~/examples$ vim README.md -``` - -Commit changes to local repository. - -```bash -~/examples$ git commit -am 'test' -[master 10074d7] test - 1 file changed, 2 insertions(+), 1 deletion(-) -``` - -## Synchronize your local repository with the remote one -```bash -~/examples$ git push -Enter passphrase for key '/home/knut/.ssh/id_rsa': **** -Counting objects: 3, done. -Delta compression using up to 4 threads. -Compressing objects: 100% (2/2), done. -Writing objects: 100% (3/3), 266 bytes | 0 bytes/s, done. -Total 3 (delta 1), reused 0 (delta 0) -To https://codeberg.org/knut/examples.git - 662e04e..10074d7 master -> master -``` diff --git a/content/git/clone-commit-via-web.md b/content/git/clone-commit-via-web.md index 1fe2309..7938277 100644 --- a/content/git/clone-commit-via-web.md +++ b/content/git/clone-commit-via-web.md @@ -6,7 +6,7 @@ eleventyNavigation: order: 30 --- -Clone, edit, commit, push and pull can be performed using Git directly from the command line, by using a Git client, or via the web interface. The first option is shown in the sections [Clone & Commit via HTTP](/git/clone-commit-via-http) and [Clone & Commit via SSH](/git/clone-commit-via-ssh). The last option is detailed below. +Clone, edit, commit, push and pull can be performed using Git directly from the command line, by using a Git client, or via the web interface. The former option is shown in the sections [Clone & Commit via CLI](/git/clone-commit-via-cli). The latter option is detailed below. The user in these examples is `knut` the polar bear and its repository is `foobar`. The repository was created via the Codeberg website including a `README.md` file. diff --git a/content/git/index.md b/content/git/index.md index cd5d511..92ca037 100644 --- a/content/git/index.md +++ b/content/git/index.md @@ -9,12 +9,11 @@ eleventyNavigation: On these pages, you will learn how to use the Git version control system with Codeberg. -There are 3 ways to interact with a Git repository hosted on Codeberg: -1. [via the SSH protocol](/git/clone-commit-via-ssh) -2. [via the HTTPS protocol](/git/clone-commit-via-http) -3. [Using the website](/git/clone-commit-via-web/) +There are 2 ways to interact with a Git repository hosted on Codeberg: +1. [via the CLI](/git/clone-commit-via-cli), either through SSH or HTTP. +2. [Using the website](/git/clone-commit-via-web/) -Option 1 and 2 require a Git client of your choice [installed on your local system](/getting-started/install-git/). +Option 1 requires a Git client of your choice [installed on your local system](/getting-started/install-git/). We recommend the use of the [SSH protocol](https://en.wikipedia.org/wiki/Secure_Shell_Protocol). It offers improved security through key-based access (stronger protection than a regular password) and better usability (no need to provide credentials on every Git action). diff --git a/content/redirects.md b/content/redirects.md new file mode 100644 index 0000000..eb7f989 --- /dev/null +++ b/content/redirects.md @@ -0,0 +1,12 @@ +--- +# This file allows redirecting URLs to prevent link rot. +pagination: + data: redirects + size: 1 + alias: redirect +redirects: + - {"from": "/git/clone-commit-via-ssh/", "to": "/git/clone-commit-via-cli/"} + - {"from": "/git/clone-commit-via-http/", "to": "/git/clone-commit-via-cli/"} +permalink: "{{ redirect.from }}" +layout: redirect +--- diff --git a/content/security/ssh-fingerprint.md b/content/security/ssh-fingerprint.md index 1db2381..d7a63f6 100644 --- a/content/security/ssh-fingerprint.md +++ b/content/security/ssh-fingerprint.md @@ -6,7 +6,7 @@ eleventyNavigation: --- When you connect to Codeberg via SSH, for example -[to clone or commit](/git/clone-commit-via-ssh/), you need to make sure that +[to clone or commit](/git/clone-commit-via-cli/), you need to make sure that you're actually connected to Codeberg's servers and not someone else's server attempting to execute a so-called [man-in-the-middle attack](https://en.wikipedia.org/wiki/Man-in-the-middle_attack).