Init Repo using Github CLI

run `gh auth login`
puis `gh repo create [name] --public`

Create Git

#1: Create a folder for this project on your local hard drive
mkdir my-project
#2: change into this folder
cd my-project
#3: initialize a new, empty Git repository here
git init
...after having written some code + created some files...
#4: add all changes to the next (= first) commit
git add .
#5: create the first commit
git commit -m "Initial commit"

Link Git to Github Repo

git remote add origin https://github.com/GithubUserName/RepoName
git remote -v #check if it worked
git push --set-upstream origin master

Add a sub module

git submodule add [github link]

Clone Private Repo

git clone https://[PAT]@github.com/[account]/[repo].git
Generate Private Acess Token at
/Settings/Developer Settings/Personal access Token
StackOF source

COMMIT BEFORE DOING ANYTHING
origin is the remote alias

Create Branch From Master

git branch [new-branch]

Create New branch from a branch

git checkout -b [new-branch] [existing-branch]

Switch Branch

git checkout [branch]

Merge Branch in Master

git checkout master
git merge [branch]

Merge Master in Branch

git checkout [branch]
git pull [origin] master

Delete branch

git branch -d [branch]

Go Back to previous Branch

git checkout -

Add and Commit

git commit -am "message"

Add Alias "ac" for the previous command

git config --global alias.ac "commit -am"

Edit comment

git --amend -m "edited message"

Rollback to a commit

git revert [commitID]

Test successive commit to find bug origin

git bisect [commit de d├ępart]
git bisect good #To Go to next commit

Nice logs

git log --graph --oneline --decorate
The goal here is to be able to deploy the website update from a push.
For this we'll use hooks and a bare repo. A bare repo is the git file without the working tree, i.e. the blueprint for all the code without the code itself.
This secific type of repo is used to be pushed to, it eliminate the risk of any problem that could come from pushing to a working tree
The hooks are script files that are called at certain point of git actions, you can put whatever you want in these files.
We are gonna use the post-receive hook to deploy a working tree under the directory we want to be able to access through nginx (by default : /var/www/html).

Local Computer -push--> /var/www/git/ (bare) -deploy--> /var/www/html

The way I've done it is quite dirty, people usully create a git user, manage permission properly etc...
I don't really care cause that's my website but it may cause problems on larger team et setup.

# log in your server
ssh your_user@server_ip_address
cd /var/www
mkdir git
mkdir html
# change ownership if needed with chown [user] [folder_name]

cd git
git init --bare
cd hooks
vim post-receive

# add those two lines to the file
#!/bin/sh
git --work-tree=/var/www/html --git-dir=/var/www/git checkout -f name_of_branch

# make it executable
chmod +x post-receive

# push from you local machine
git remote add origin ssh://your_user@server_ip_address:/var/www/git/

website to dowload a specific directory from a repo

References