Refactor HowTo_Git post
Before Width: | Height: | Size: 110 KiB |
Before Width: | Height: | Size: 87 KiB |
Before Width: | Height: | Size: 68 KiB |
Before Width: | Height: | Size: 76 KiB |
Before Width: | Height: | Size: 104 KiB |
Before Width: | Height: | Size: 48 KiB |
Before Width: | Height: | Size: 30 KiB |
Before Width: | Height: | Size: 63 KiB |
Before Width: | Height: | Size: 90 KiB |
Before Width: | Height: | Size: 39 KiB |
Before Width: | Height: | Size: 27 KiB |
Before Width: | Height: | Size: 72 KiB |
Before Width: | Height: | Size: 32 KiB |
@ -1,147 +0,0 @@
|
||||
+++
|
||||
title = "Beginner's guide to Git"
|
||||
date = 2024-07-19
|
||||
hidden = true
|
||||
+++
|
||||
|
||||
## 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](https://github.com/).
|
||||
|
||||
## How to download someone's repository?
|
||||
|
||||
1. Clone it with `git clone REPO_LINK`
|
||||
```bash
|
||||
git clone https://github.com/oneshotws/hackerProg
|
||||
```
|
||||
First time - we will get prompt, answer `yes` (details below).
|
||||
|
||||
|
||||
## Getting started - How to make repo?
|
||||
|
||||
0. __Register__ on Github
|
||||
|
||||
1. Create a Git __repository__
|
||||
![](./images/10.png)
|
||||
![](./images/11.png)
|
||||
2. Choose a __license__
|
||||
- __"MIT License"__ if you don't know what to choose
|
||||
![MIT](./images/21.png)
|
||||
- __"GNU GPLv3"__ if you want your project to be free software.
|
||||
![GNU GPLv3](./images/22.png)
|
||||
|
||||
3. __Clone__ (download) the repository `git clone REPO_LINK`.
|
||||
|
||||
Get repo link (click on "Code"): ![](./images/31.png)
|
||||
If we clone via SSH link, we will get promt:
|
||||
```bash
|
||||
~ ➤ 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:
|
||||
|
||||
```bash
|
||||
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.
|
||||
<!-- ![](./images/32.png) -->
|
||||
|
||||
|
||||
4. __Generate__ an SSH key (if you don't have one!) - `ssh-keygen` and press enter 3 times:
|
||||
```bash
|
||||
~ ➤ 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
|
||||
```
|
||||
<!-- ![](./images/34.png) -->
|
||||
Next we click the "add a new public key" hyperlink and paste in our SSH public key.
|
||||
![](./images/33.png)
|
||||
![](./images/35.png)
|
||||
(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`:
|
||||
|
||||
![](./images/36.png)
|
||||
![](./images/37.png)
|
||||
<!-- ```bash -->
|
||||
<!-- ~ ➤ cd hackerProg -->
|
||||
<!-- hackerProg ➤ ls -->
|
||||
<!-- LICENSE main.go README.md -->
|
||||
<!-- hackerProg ➤ bat main.go -->
|
||||
<!-- ───────┬────────────────────────────────────────────────────────────── -->
|
||||
<!-- │ File: main.go -->
|
||||
<!-- ───────┼────────────────────────────────────────────────────────────── -->
|
||||
<!-- 1 │ package main -->
|
||||
<!-- ───────┴────────────────────────────────────────────────────────────── -->
|
||||
<!-- ``` -->
|
||||
|
||||
|
||||
|
||||
5. __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`.
|
||||
![](./images/41.png)
|
||||
- `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.](https://ohshitgit.com/)
|
||||
|
||||
---
|
||||
|
||||
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 >}}
|
||||
|