adding images and starting setup guide

This commit is contained in:
Ric Harvey 2024-05-01 17:40:32 +01:00
parent fe52e461d7
commit ec77305ec2
Signed by: ric
GPG key ID: 7FDEB4C0C7D5CB61
2 changed files with 52 additions and 0 deletions

View file

@ -1,5 +1,7 @@
# Git Guide
In this guide we are going to show you how to use Gitlab, however before we get going setting thingsup it's good to get an understanding of however the tool works that powers Gitlab (and Github). So let's dive in and take a look.
## So what is Git?
At it's core git is a versioning system to store your code also known as a version control system (VCS). It was developed in 2005 by the creator of the Linux Kernel, Linux Torvalds.
@ -65,6 +67,8 @@ gitGraph
commit
```
Using branches to manage your code is often reffered to as Pull Request Workflow, its great for teams for sharing knowledge and encourages code reviews from other team members, but that can introduce delays in getting your feature merged.
### HEAD
The most recent commit on the currently checked-out branch is indicated by something reffered to as the HEAD. This is a pointer to any UID within the repository and when new commits are pushed the HEAD updates. This is how git knows to compare your commit with the HEAD to make a diff on the remote repository.
@ -90,8 +94,56 @@ gitGraph
## Forks
Forks are kind of like branches, but instead of just making a slight deviation from main you actually get a full working repostity of your own. Making commits and pushes will only ever effect your git repo however there is a tie back to the original repository that allows you to pull updates from upstream. Developers can then make merge/pull requests backup stream to the main project. This is particularly useful if you want to make contributions to some code that doesn't belong to your team so you can't create a branch on the main repo. This is known as the Forking Workflow.
There are other workflows however such as the Gitflow Workflow which involves having several long lived branches such as main, develop and release branches. You can also completely ignore all these features and do something called Trunk-Based development where everyone commit's to main, and this is good for rapid itteration but can give you merge conflict nightmares!
![Git Merge Conflicts](./img/merge.gif)
## Getting Setup
Right thats enough theory lets get you set up to start with! The commands I'm about to show you will work on MacOS, Linux or windows. You first need to make sure you have git installed on your system, which you can get from [here](https://git-scm.com/). On MacOS and Linux you can then use your native terminal to run the ```git``` command and on windows you'll want to open the git bash program.
## Username and Email
When you pull a private repository or push to a repository you have two options use HTTPS or SSH. You should use SSH where possible, HTTPS can be used when you are cloning someone elses work to use but don't intend on pushing back to that repository.
Now hopefully you'll have a login to [Gitlab](https://gitlab.com) or [Github](https://github.com) if not go and set one up now.
The first thing you'll need to do is set up your name, so git can use this to show to other who commited the code. Simply run the following in your terminal.
```bash
git config --global user.name "Ric Harvey"
```
Now lets go ahead and set up your email address, which will be used to identify you when you commit code and login via SSH.
```bash
git config --global user.email ric@rics-superdomain.com
```
Right now we need to generate you an SSH key. These come in two parts private and public. You are going to want to protect your private key and not let anyone else get a copy of it as this is your key to push code on Gitlab or your repository.
In your terminal again run:
```bash
ssh-keygen -t rsa -b 2048 -C "<comment>"
```
Press ``enter`` to the next question which will have an output like this
```bash
Generating public/private ed25519 key pair.
Enter file in which to save the key (/home/user/.ssh/id_rsa):
```
Now enter a passphrase for your key, alternatively you can leave this blank but best practice says you should protect it!
```bash
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
```
## Advanced Setup (Highly Recommended)

BIN
img/merge.gif Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 MiB