5.4 KiB
+++ title = "HowTo Git" date = 2024-07-19 +++
WhatIs Git?
Git is a version control system. It is a program that allows you to roll back changes in files to point where they were previously saved.
It also helps multiple people work on a project. Thus it can combine changes made by several developers.
Repository (or repo) - directory with all source code and other necessary files for program to work + it contains Git metadata which allows to roll back files.
There are services that provide access to git repositories, the most popular is GitHub.
HowTo create repository?
How to create remote repository
-
Register on Github
-
Choose a license
How to create local repository
- Run
git init
in directory with code
HowTo download repository?
- Clone (download) it with
git clone REPO_LINK
git clone https://github.com/oneshotws/hackerProg
First time you will get SSH prompt, answer yes
.
~ ➤ git clone https://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])? yes
Link types
Git allows to clone repositories via few HTTPS and SSH link
HTTPS - https://github.com/oneshotws/hackerProg.git
(.git in end isn't necessary)
SSH - git@github.com:oneshotws/hackerProg.git
You can see them by clicking on "Code":
In case of SSH link you need to be authentificated to be able to use them. Otherwise you will get following error:
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.
HowTo authentificate?
To be able to upload changes to repository - we need to be authorized and authentificated for GitHub via our console.
- Tell who you are (authentificate)
Run following commands:
git config --global user.email "YOUR_EMAIL@EXAMPLE.COM"
git config --global user.name "YOUR VISIBLE NAME"
- Proof who you are (authorize)
For that we need to associate SSH key with our account.
- 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 (that ends with
.pub
) SSH key withcat
and copy it.
~ ➤ cat ~/.ssh/id_ed25519.pub
ssh-ed25519 AAAAC3NzaC1lZDI1HEX5AAAAIIMaB2mluyXjROHI8GJ2o9xfvj+uiol/GbPnwJDzZkFm username@hostname
- Add key to GitHub
Navigate to Settings -> SSH and GPG keys -> New SSH key
Paste your public key:
HowTo upload changes to your repo?
-
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
.git add .
- adds all new files to the repository, so git will start track their changes (files in repository folder aren't tracked, we even can make git ignore specific files so files with our secrets won't be public)git commit -am 'new feature description'
- saves (commits) changes to the repository that you can rollback to later.git push
- uploads changes to GitHub.
After that, our local changes will be displayed on github.
Advanced
Git can be used in more advanced usages, like:
- get bug reports (via Issues tab)
- get notifications for new bug reports, releases...
- upload changes to someone's else repository
- allow others to make changes to your repository
- review and merge their changes
- fork repository
- wiki, web pages, automatization, webhooks, etc...
Also you need to keep in mind that your repository isn't private by default and if you write there private information / passwords / keys - advisory will use it to harm you.
And even if you will make repo private - I wouldn't trust Microsoft (owner of GitHub) to keep my secrets. So I would host my own private Git service.
{{< source >}} My PHD2 presentation {{< /source >}}