Casual_blog/content/tech/Beginners_guide_to_Git/index.md
2024-07-19 15:00:37 +03:00

5.3 KiB

+++ title = "Beginner's guide to Git" date = 2024-07-19 +++

WhatIs Git?

Git is a version control system. It is a program that allows you to roll back changes to files before they were previously saved.
It also helps multiple people work on a project. Thus it can combine changes made by several developers.

There are services that provide access to git repositories, the most popular is GitHub.

How to download someone's repository?

  1. Clone it with git clone REPO_LINK
git clone https://github.com/oneshotws/hackerProg

First time - we will get prompt, answer yes (details below).

Getting started - How to make repo?

  1. Register on Github

  2. Create a Git repository

  3. Choose a license

    • "MIT License" if you don't know what to choose MIT
    • "GNU GPLv3" if you want your project to be free software. GNU GPLv3
  4. Clone (download) the repository git clone REPO_LINK.

    Get repo link (click on "Code"): If we clone via SSH link, we will get promt:

~ ➤ git clone git@github.com:oneshotws/hackerProg.git
Cloning into 'hackerProg'...
The authenticity of host 'github.com (140.82.121.4)' can't be established.
ED25519 key fingerprint is SHA256:+DiY3wvvV6TuJJhbpZisF/zLDA0zPMSvHdkr4UvCOqU.
This key is not known by any other names.
Are you sure you want to continue connecting (yes/no/[fingerprint])?
  • write yes, press enter. This should happen only once.
    And we will get an error:
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added 'github.com' (ED25519) to the list of known hosts.
git@github.com: Permission denied (publickey).
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

Previously GitHub said we have not added the SSH key to our account.

  1. Generate an SSH key (if you don't have one!) - ssh-keygen and press enter 3 times:
~ ➤ ssh-keygen
Generating public/private ed25519 key pair.
Enter file in which to save the key (/home/casual/.ssh/id_ed25519):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/casual/.ssh/id_ed25519
Your public key has been saved in /home/casual/.ssh/id_ed25519.pub
The key fingerprint is:
SHA256:ut0/9NgtyQEmOozmVOUBFbnfAgScz9IkwPCKalOCff0 casual@Casual-PC
The key's randomart image is:
+--[ED25519 256]--+
|    .o.oo=oo     |
|     .. + *      |
|      .  X o     |
|.. . o  o O o    |
|..o.o .+So = o   |
| .o.  +o+   + o  |
|.o   +. E. . * + |
|. .   .o .  o * .|
|      . . .... . |
+----[SHA256]-----+

Output the public SSH key with cat and copy it.

~ ➤ cat /home/casual/.ssh/id_ed25519.pub
ssh-ed25519 AAAAC3NzaC1lZDI1HEX5AAAAIIMaB2mluyXjROHI8GJ2o9xfvj+uiol/GbPnwJDzZkFm casual@Casual-PC

Next we click the "add a new public key" hyperlink and paste in our SSH public key. (note - screenshot have different key)
This should happen only once.

After that we will be able to download repositories via SSH and upload changes (git push), what will prevent problems in the future.
Run git clone git@github.com:oneshotws/hackerProg.git:

  1. Develop your program.
    Once you make the changes you want, upload them to the repository using:
    git add . && git commit -am 'new feature' && git push.

    However, you will probably find that git doesn't know who you are, so it will ask you to add your email and name with git config.

    • git add . - adds new files to the repository (not all files are tracked in folder that will be uploaded to remote repository)
    • git commit -am 'new feature description' - saves (commits) changes to the repository that you can rollback to later.
    • git push - uploads them to GitHub.

    After that, our local changes will be displayed on github.


Other typical Git problems.


Btw, it's experemental post. Do you like this approach that we deal with problem as we are doing it first time together? Or do you prefer more easier to read - step by step (HowTo) guide?

{{< source >}} My PHD2 presentation {{< /source >}}