Documentation/content/git/clone-commit-via-cli.md
Otto Richter 2bda61e74d Diverse changes (#189)
a bunch of (typo) fixes, additions, rewordings

Update references

- remove mentions of the master branch, as it's removed for many repos
and might change in the future for others (fixes some dead links)
- remove mentions of moved repos with our official examples
- some on-the-fly additions or rewordings

Close #186 foobar->examples

Co-authored-by: fnetx <git@fralix.ovh>
Co-authored-by: fnetX <git@fralix.ovh>
Reviewed-on: https://codeberg.org/Codeberg/Documentation/pulls/189
Co-authored-by: Otto Richter <fnetx@noreply.codeberg.org>
Co-committed-by: Otto Richter <fnetx@noreply.codeberg.org>
2022-01-21 11:36:38 +01:00

3.7 KiB

eleventyNavigation
key title parent order
CloneCommitviaCLI Clone & Commit via CLI Git 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 former option is shown below. The latter option is detailed in the section Clone & Commit via Web.

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.

HTTP

~$ 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.

Warning


Please make sure that before connecting to Codeberg via SSH, you have verified Codeberg's SSH fingerprint!

If you have set up a passphrase, you will be asked for it.

~$ 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:

~$ cd examples
~/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:

~/examples$ git commit -am 'test'
[main 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.

If you are using HTTP, you will be asked for your Codeberg username and password.

~/examples$ git push
Username for 'https://codeberg.org': knut
Password for 'https://knut@codeberg.org':
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  main -> main

Pull

Pulling synchronizes the modifications (commit) from the remote repository on Codeberg to the local one. Pulling is important when you work on different computers to make sure that all computers are on the same stage. It is even more important when you have collaborators on a project; they might change the files too, so you need to pull these modifications before you start working. Because of that, it is recommended to pull before pushing.