Monday, September 27, 2021

Git unplugged notes

Git unplugged notes



Rebase issue

# If someone rebases on public branch, after pull all others could see:

Your branch and 'origin/branch1' have diverged,

and have 2 and 3 different commits each, respectively.

Solution

git fetch origin

git reset --hard origin/main

src stackoverflow



Rebase issue

Your branch is ahead of 'origin/master' by 3 commits

Solution

git fetch -p # clean up local branches

git pull --rebase # pull and rebase my local commits on top of incoming

Better solution (unchecked)

Step 1 : git checkout branch1

Step 2 : git pull -s recursive -X theirs # merge strategies

Step 3 : git reset --hard origin/branch1



Rebase issue explained (long)

git rev-list --count --left-right branch1...upstream

git rev-list --count --left-right origin/master...HEAD

*

# to see if the local repository is ahead, push needed:

git rev-list origin..HEAD

# to see if the local repository is behind, pull needed:

git rev-list HEAD..origin

# if you have numbers for both, then the two repositories have diverged:

git rev-list --count --left-right origin/master...HEAD

src: stackoverflow

src: https://stackoverflow.com/a/40990959

src-long: https://stackoverflow.com/a/66981730



# squash - reset soft:

#git reset --soft master

git reset --soft origin/master

git add -A

git commit

git push --force



# squash - reset to merge-base:

git checkout branch1

git reset $(git merge-base master $(git branch --show-current))

git add -A

git commit

git push --force

# src: https://stackoverflow.com/questions/25356810/git-how-to-squash-all-commits-on-branch

# Note: git merge-base branch2 branch3



Squash

# squash - merge squash:

git checkout origin/master

git merge --squash origin/branch1

git commit

git push --force



Git branch_name vs refs

git show-ref origin/main

1. If $GIT_DIR/<refname> exists, that is what you mean (this is usually useful only for HEAD, FETCH_HEAD, ORIG_HEAD, MERGE_HEAD and CHERRY_PICK_HEAD);

2. refs/<refname> if it exists;

3. refs/tags/<refname> if it exists;

4. refs/heads/<refname> if it exists;

5.  refs/remotes/<refname> if it exists;

6. refs/remotes/<refname>/HEAD if it exists.

src: stackoverflow.com

Long aside: how this all works (read only if sufficiently curious) :

src: stackoverflow.com



Git server repository (docker git repo)

Alpine Git client

JKarlos Docker Git server

Gogs and Podman Git server

Gogs Git server

Gogs by Pirates - GitHub like Git server

Gitea in Docker - demo - github

GitColony docker server - obsolete



Git server:

Google it:

https://www.google.com/search?q=gnu+gpl+git+server

Git server list - wiki:

https://en.wikipedia.org/wiki/Git#Git_server

Gerrit:

Home: https://www.gerritcodereview.com/

Wiki: https://en.wikipedia.org/wiki/Gerrit_(software)

GitOlite:

https://gitolite.com/gitolite/index.html

Wiki says: External projects like gitolite, which provide scripts on top of git software to provide fine-grained access control.

*

FLOSS:

Gogs

Gitea = fork of Gogs



Git Web interface self-hosted:

https://www.google.com/search?q=git+web+interface+self-hosted

Options – list – good overview:

https://www.cyberciti.biz/open-source/github-alternatives-open-source-seflt-hosted/

GitLab = web git, “Confluence” wiki, “Jira” tracker

https://gitlab.com/gitlab-org/gitlab-foss

Gitea – community fork of Gogs:

https://gitea.io/

Savannah = GNU = free software foundation (FSF)

http://savannah.gnu.org/projects/administration

GitBucket – Open source

https://github.com/gitbucket/gitbucket

Gogs - self hosted Git:

https://gogs.io/

*

Awesome Selfhosted:

https://github.com/awesome-selfhosted/awesome-selfhosted

GitWeb:

https://git-scm.com/book/en/v2/Git-on-the-Server-GitWeb

*

BitBucket.org

GitHub.com


Git web UI – including proprietary and closed-source:

https://www.slant.co/topics/1440/~best-self-hosted-web-based-git-repository-managers

https://www.slant.co/topics/425/~best-git-web-interfaces



Thursday, August 12, 2021

Lodě Sázava 2021 (FAV)


KDY / WHEN:

Neděle / Sunday

15. 8. 2021

9:00 – 18:00



TRASA / ROUTE:

Sázava

Sázava - mapy

*

VLAK / TRAIN:

from destination to start for car drivers

Kácov (dest) - Zruč n. S (start)

Kácov (dest) - Zruč n. S (start) - Friday 22

TRAIN WALK:

Zruc NS from Train to start Camp Rakosi

*

START:

Výdej lodí / issuing canoes: 9.00–10.00

Zruč nad Sázavou

Kemp Rákosí

Start - Google maps point

bisport premise ZrucNS

*

PŘESKOČIT / AVOID (pomalí / slow service):

Tůmův Chabeřický mlýn

*

ODBOČKA / FORK (suggested):

Želivka fork, short break, refreshment, crystal clear cold water

*

BREAK (doporučený / suggested):

Kemp Omaha - gallery

nice weir

good kiosk - sausages, local beer, pancakes, coffee

it was perfect on last summer, I hope they keep the quality

*

CÍL / END:

Kácov

Kácov rental - Google maps point

Sběr lodí / return canoes: 15.00–19.00

bisport premise Kacov



KDO / WHO:

2 MarS single

2 MaD + Smita

3 Petr + Tamara + Ráša

2 Jiří + tatínek



PÚJČOVNA / RENTAL:

Bisport Kácov s.r.o., Kácov 158

https://www.bisport.cz/pujcovna-lodi

Mail: info@bisport.cz

Tel: + 420 777 335 618



PLATBA / PAYMENT:

Č.Ú. / Account: ***

Zpráva / Message: Your Name, Sazava 2021

*

ČÁSTKA / AMOUNT:

MarS: 399 CZK

MaD: 399 CZK

Jiri 2-seats: 399 CZK

Petr 3-seats: 555 CZK

*

PÚV CENA / ORIG PRICE:

Vydra 2 seats: 420 CZK / 1 canoe

Rivera 3 seats: 585 CZK / 1 canoe

sleva / discount: 5%



PÚJČOVNA / RENTAL – others:

Dronte (na Sázavě outsourcuje přes BiSport)

Samba (Ohře Ondra K a Anička letos, asi i loni a dříve)

Půjčovna Samba – stejná



KEYWORDS:

Canoe kanoe kánoe Sázava Sazava 2021 FAV



Sunday, July 11, 2021

Docker networking


Create bridge

docker network create -d bridge mars_bridge


Run container inside specific network (i.e. Redis and Redis CLI)

docker run --name some-redis --network mars_bridge --rm -d redis

docker run -it --network mars_bridge --rm redis redis-cli -h some-redis


Connect container to network

docker network connect mars_bridge some-redis


Disconnect container from network

docker network disconnect mars_bridge some-redis


List Docker networks

docker network ls


Remove Docker network

docker network rm mars_bridge


Remove all unused networks

docker network prune


Inspect Docker network

docker network inspect mars_bridge


Inspect with formatted output

docker inspect --format='{{json .NetworkSettings.Networks}}'  some-redis

docker inspect --format="{{json .NetworkSettings.Networks}}" some-redis

docker inspect --format="{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}" some-redis


Sources

Docker - networking containers

Docker Hub - Redis (as an example of Docker-networked container)


Docker notes unplugged

 My Docker notes - crossroads



Docker orchestration with Kubernetes k8s

My Docker Kubernetes k8s notes



Docker memory CPU limits (Windows)

My Docker limits - cpu memory notes



Docker network configuration

My Docker networking notes

src: docs.docker.com



Docker Swarm stack deploy

My Docker Swarm stack deployment notes

src: docs.docker.com



See also

My AWS - Amazon Web Services - notes

DockerCon 2021 - conference

PlayWithDocker - play, 101tut, lab, get started, training


Tuesday, July 06, 2021

AWS - Amazon Web Services - notes

AWS - Amazon Web Services - notes

My unsorted notes about AWS


AWS general xroad

Home

Console

* console FFT Frankfurt

CLI

Sign in

Trainings all

Trainings and Certifications blog post

aws.training site


10 miutes tutorials crossroad

10 min tut xroad

WordPressServerLessReactLinux VMMySQLStatic S3PostgreSQL


Popular AWS - services crossroads

Free Tier, Elastic Beanstalk, DynamoDB, RDS (Relational Database Service), CloudFront, Glacier


LightSail

 - servers and services management console

 -  easily setup your service

LightSail tutorials home

LightSail home page


EC2

- Elastic Compute Cloud

EC2 pricing

EC2 get started - LAMP, Elastic, WordPress, etc

* WordPress 10 min tut


S3

- Simple Storage Service

S3 home

S3 get started



Lambda

 - serverless computing

Lambda home

Lambda - get started - crossroad

Lambda - resources

Lambda - build basic web app

Lambda - ServerLess web app tutorial

* ServerLess with Lambda, API GateWay, Amplify, DynamoDB, Cognito


Sunday, March 07, 2021

PostgreSQL intro

PostgreSQL :



psql CLI :

psql option dbname username

i.e. :


export PGPASSWORD=pg-pass

psql -h pg-host -U postgres


psql -c '\x' -c 'SELECT * FROM current_catalog;'


echo '\x \\ SELECT * FROM current_catalog;' | psql


psql <<EOF

\x

SELECT * FROM current_catalog ;

EOF


src: psql CLI doc



CLI FILES :

PasswordLess login:

Linux : ~/.pgpass - pg pass

Win :   %APPDATA%\postgresql\pgpass.conf

format: hostname:port:database:username:password

env :   set PGPASSFILE=C:\Program Files\someapp\pgpass.conf

note :  if env PGPASSWORD is set, ~/.pgpass is ignored

nopass: sleeplessbeastie

bash :  chmod u-x,go-rwx ~/.pgpass



CLI SWITCHES :

-c command

-d dbname

-h host

-U user

-W --password

-f command-input-file

-l == list all available databases

\x = toggle expanded table formatting mode

-o output-file.txt



CLI commands :

\l - Display database

\list

\c - Connect to database

\conninfo

\dn - List schemas

\dt - List tables inside public schemas

\dt schema1. - List tables inside particular schemas. For eg: 'schema1'.

stackexchange



Create table :

CREATE TABLE accounts (

user_id serial PRIMARY KEY,

username VARCHAR ( 50 ) UNIQUE NOT NULL,

password VARCHAR ( 50 ) NOT NULL,

email VARCHAR ( 255 ) UNIQUE NOT NULL,

created_on TIMESTAMP NOT NULL,

        last_login TIMESTAMP 

);

\d = list tables

\d accounts = describe table accounts

DROP TABLE accounts ;

CREATE SCHEMA myschema ;

CREATE TABLE myschema.mytable ... ;

DROP SCHEMA myschema ;

SELECT CURRENT_TIMESTAMP;

src: tutorialspoint

src: postgresqltutorial - M;N table relation



Show current info - session, user, schema, database :

SELECT current_database();

SELECT * FROM current_catalog;

SELECT current_catalog;


SHOW DateStyle;

SHOW search_path ;

SET search_path TO myschema ;


SELECT * FROM pg_stat_activity;

SELECT * 

FROM pg_stat_activity 

WHERE datname = 'dbname' 

 and state = 'active';

src: stackoverflow - stackoverflow



Postgres with Docker :

:: Start Postgres

docker run --rm --name mars-postgres -e POSTGRES_PASSWORD=pg-pass -d postgres

:: Create bridge

docker network create -d bridge mars_bridge_postgres

:: Connect already existing container to network

docker network connect mars_bridge_postgres mars-postgres


:: Disconnect container from network
docker network disconnect mars_bridge_postgres mars-postgres

:: Stop Postgres
docker container stop mars-postgres

:: Remove Docker network
docker network rm mars_bridge_postgres


:: CLI
@echo Pass is pg-pass
@rem PGPASSWORD=pg-pass
@rem docker run -it --rm --network mars_bridge_postgres postgres psql -h mars-postgres -U postgres
docker run -it --rm --network mars_bridge_postgres postgres bash -c "PGPASSWORD=pg-pass psql -h mars-postgres -U postgres"



PG tutorial :

https://www.tutorialspoint.com/postgresql/postgresql_quick_guide.htm

https://www.postgresqltutorial.com/


PG data types :

https://www.postgresqltutorial.com/postgresql-data-types/


Import CSV to SQL  in Postgre :

https://www.postgresqltutorial.com/import-csv-file-into-posgresql-table/


Export SQL to CSV from Postgre :

https://www.postgresqltutorial.com/export-postgresql-table-to-csv-file/


PG Admin :

https://www.pgadmin.org/

https://www.pgadmin.org/download/

Saturday, January 23, 2021

Git cheat sheet


Clone git repo

git clone https://github.com/user/project.git

git clone ssh://git@github.com/user/project.git

gh repo clone user/project




GitHub how to

Get started with GitHub

GitHub profile

GitHub email settings




Create new repo (add existing project to Git)

# Create also remote repository, i.e. create repo on GitHub

git init -b main # previously master, init.defaultBranch

echo "New project" > README.md

git add . # or: git commit -a

git commit -a -m "Initial commit"

git remote add origin https://github.com/user/project.git

git remote add origin git@github.com:username/project.git

git remote -v # verify

git push -u origin main # previously master

# configure default name of main branch:

git config --global init.defaultBranch main

see also:

Create new repo in GitHub (how to)

Add existing project to GitHub




Pull

git pull # update (fetch) from remote tracking upstream, merge into current branch

git pull origin # update from origin

git pull origin branch1 # update from origin, merge remote branch1 into current branch

# or:

git fetch origin

git merge origin/branch1

git pull –-all # fetch all remotes



Show branches

# local:

git branch -l

remotes:

git branch -r

# all:

git branch -a  # remotes prefixed with "remotes/"

current:

git branch --show-current

branch parent:

git parent

# git parent alias in Windows Cmd:

git config --global alias.parent2 "!git show-branch | grep '*' | grep -v \"$(git rev-parse --abbrev-ref HEAD)\" | head -n1 | sed 's/.*\[\(.*\)\].*/\1/' | sed 's/[\^~].*//' #"

src: stackoverflow

# git parent alias in Linux or Windows Git Bash:

git config --global alias.parent2 "!""git show-branch | grep '*' | grep -v \"\$(git rev-parse --abbrev-ref HEAD)\" | head -n1 | sed 's/.*\[\(.*\)\].*/\1/' | sed 's/[\^~].*//' #"

src: stackoverflow

# creates following alias in ~/.gitconfig :

[alias]

    parent = "!git show-branch | grep '*' | grep -v \"$(git rev-parse --abbrev-ref HEAD)\" | head -n1 | sed 's/.*\\[\\(.*\\)\\].*/\\1/' | sed 's/[\\^~].*//' #"



Switch to another git branch

# switch to and reset (-Blocal branch or create new local :

git checkout -B branch1 origin/branch1

# switch to existing local branch:

git checkout branch1

# since git 2.23.0:

git switch branch1 origin/branch1



Clone/Create branch and switch into it

# create (-b) new branch1 from origin/master^0, checkout (optionally: --track, --no-track)

git checkout -b branch1 origin/master^0 --

More at StackOverflow



Push new local branch to remote

git push -u origin HEAD

git push -u origin refs/heads/branch1:branch1



Merge branch1 to master

git checkout origin/master

git merge origin/branch1

git push

git push origin HEAD

git push origin refs/heads/master:master



Merge remote branch1 into current branch

git pull origin branch1

git push



Merge Squash

git checkout origin/master

git merge --squash origin/branch1

git push



Merge without merge commit / avoid merge commit

git checkout origin/master

git merge --ff-only origin/branch1

git push

src: Q: stackoverflow

A: stackoverflow



Merge using Patch

git checkout feature

git diff main > feature.patch

git checkout main

patch -p1 < feature.patch

git add .

src: stackoverflow



Merge conflicts - resolve conflicts

resolve conflicts:

vim file1.txt # resolve conflicts

git mergetool # resolve conflicts

add (stage) resolved changes to index:

git add -A -f -- file1.txt add (-A now equiv to ., including removal)

git add -u add all modified (previously added)

commit resolved changes:

git commit -a -m "commit message" add and commit

git commit -F C:\git\project1\.git\MERGE_MSG --



Merge - resolve conflicts helpers

git status

git log --merges # print only merge commits

git diff

git checkout

git merge --abort

git reset

git mergetool # uses merge tool to resolve merge conflicts

git am --show-current-patch # see failed patch (from merge)

see: atlassian - merge conflicts



Merging strategies

ours

theirs

patience

octopus (?)

diff-algorithm

see: atlassian - merge strategy



Rebase

git checkout origin/branch1

git rebase origin/master

git add fixed_file.txt

git commit -m "fixed conflict"

git rebase --continue # skip, abort

git push --force



Rebase pull

git pull --rebase

Config:

git config branch.autoSetupRebase always

git config --global pull.rebase true

git config --global pull.rebase preserve # set up Git to automatically rebase upon pull

src: stackoverflow



# Change parent branch:

git rebase --onto origin/newBase



# Interactive rebase (squash, drop, ...)

git rebase --interactive origin/master

git rebase -i origin/master

# p, pick = use commit

# r, reword = use commit, but edit the commit message

# e, edit = use commit, but stop for amending

# s, squash = use commit, but meld into previous commit

# f, fixup = like "squash", but discard this commit's log message

# x, exec = run command (the rest of the line) using shell

# d, drop = remove commit

See more about Rebase



The Golden Rule of Rebasing

Never rebase public branches

# Rebase public branch – if ever:

git --fork-point



Undo git rebase

git reset --hard ORIG_HEAD # rebase saves start point


git reflog # find head commit before rebase

git reset --hard "HEAD@{2}"# reset to commit before rebase


# proper config:

git config core.logallrefupdates=true



Push

git push # Push to tracked/upstream/remote

git push origin branch1 # Push to branch1

git push -u origin branch1 # Push to branch1 and set upstream

git push -u origin local1:remote1 # push local1 to remote1 and set-upstream

See Push default



Push force

git push --force-with-lease

git push --force-with-lease origin X

src: stackoverflow

src: stackoverflow



Push tags

git push --tags # tags are not pushed automatically



Push all

git push --all # all branches



Delete branch

# Delete local:

git branch -d branch1

# Force delete local

git branch -D branch1

# Delete remote:

git push --delete origin/branch1

# SOLVED: fatal: --delete doesn't make sense without any refs

git push origin :branch1 # actually deletes branch1



Rename branch

git branch -m branch1 # rename current branch to branch1



Prune

# Delete local branches without remotes

git remote prune origin --dry-run # prunes tracking branches not on the remote

git fetch -p

git fetch -p && for branch in $(git branch -vv | grep ': gone]' | awk '{print $1}'); do git branch -D $branch; done

Note: see differences between differences between git remote prune, git prune, git fetch --prune, etc



Git tag

# Tags are ref's pointing to git history. Types: 

lightweight tags (absence of the -a, -s, -m), 

annotated tags


# Lightweight tag (absence of the -a, -s, -m)

# Create a new tag checksum and store it in the .git/ of project's repo

git tag v1.4


# Annotated Tag

# full objects in the Git database (store the tagger name, email, and date)

git tag -a v1.4


# Add (commit-like) tag message:

git tag -a v1.4 -m "my version 1.4"


# List tags

git tag

git tag -l *-rc*


# Tag old commit

git log --pretty=oneline

git tag -a v1.2 commit-id


# fatal: tag 'v0.4' already exists => force

git tag -a --force v1.4 commit-id


# Push tag:

git push origin v1.4


# Checkout tag:

git checkout v1.4


# Delete tag:

git tag -d v1


# Prune tags:

git fetch --prune-tags

src: atlassian.com



Reset branch (move back in history)

# reset your branch to master and destroy changes:

git reset --hard origin/master

# reset your branch to master and keep changes as commited:

git reset --soft origin/master

# reset your branch to master and mixed (not added to index):

git reset --mixed origin/master

Reset Demystified



Commit References (move back in history)

HEAD~ and HEAD^

~ most of the time

^ on merge commits

*

Mnemo:

Tilde ~ is almost linear in appearance and wants to go backward in a straight line

Caret ^ suggests an interesting segment of a tree or a fork in the road

*

Order of Parent Commits

Show 89e4fcb0dd’s immediate parents in sequence:

git rev-parse 89e4fcb0dd^1 89e4fcb0dd^2 89e4fcb0dd^3

src: good article: stackoverflow



Cherry pick

# Syntax:

git cherry-pick commit-sha

# i.e.: you want to get f into Main:

    a - b - c - d   Main

         \

           e - f - g Feature

git checkout main

git cherry-pick f

Options

git cherry-pick -x f # generate standard commit message – keep track of origin of commit

   https://git-scm.com/docs/git-cherry-pick#Documentation/git-cherry-pick.txt--x

git cherry-pick --edit f # you can edit commit message

git cherry-pick --no-commit f # do cherry pick but do not commit and keep changes in working directory

git cherry-pick --signoff f # add signoff signature to end of cherry-pick commit message

git cherry-pick --abort --continue –quit # when solving conflicts

Copy notes attached to cherry pick:

git notes copy <from> <to>

src: atlassian: cherry-pick

https://stackoverflow.com/questions/9339429/what-does-cherry-picking-a-commit-with-git-mean

example: https://stackoverflow.com/a/30218784

*

see also: atlassian: merge-strategy



Revert file

remove untracked including ignored:

git clean -fd # remove untracked directories and untracked files

git clean -fX # remove only ignored files

git clean -fx # remove directories, ignored and non-ignored untracked files (include build target)

src: stackoverflow

answer: stackoverflow

-n, --dry-run # dry run

git clean -i # interactive

git add --all && git reset --hard HEAD

src: https://stackoverflow.com/a/37614185


# undo/revert local changes:

git reset --hard

git stash

git reset HEAD file1.txt # unstage to current commit

git checkout -- file1.txt

git checkout HEAD -- file1.txt


# revert (remove) uncommited file:

git rm --cached -f -- file1.txt

git reset file1.txt

See more at Revert all local changes



Stash

# simple:

git stash

git stash -u # include ignored and untracked

git stash pop


# name stash:

git stash save "my stash name"


# list

git stash list


# apply and keep

git stash apply stash@{0} # apply and keep

git stash pop # apply/pop and drop


# branch from stash

git stash branch branch1 stash@{2}


# view details

git stash show


# delete

git stash drop stash@{1}


# delete all

git stash clear



Git log

git log --oneline --decorate

git log --graph --oneline --decorate

git log --pretty=format:"%cn committed %h on %cd"

git log -3 # 3 lines

git log main..feature

git log --no-merges

git log -–merges

src: https://www.atlassian.com/git/tutorials/git-log

# Pretty format

git log --all --decorate --oneline -–graph # "A Dog" 

git config --global alias.adog "log --all --decorate --oneline --graph"

src stackoverflow.com



Ref log

# Show git commands history:

git reflog

git reflog --relative-date

git reflog --all

git reflog show

See more Many undo possibilities

See on Atlassian



Push default

git config --global push.default matching # old default behavior

git config --global push.default simple # new default behavior

See default git push

See push -u



Upstream config

# snippet of git config – refs remotes upstreams :

git config --local -–list | grep '^remote'

# remote and refspec def :

remote.origin.url=https://github.com/username/project.git

remote.origin.fetch=+refs/heads/*:refs/remotes/origin/*

# branch master :

git config --list | grep "^branch"

branch.master.remote=origin

branch.master.merge=refs/heads/master

src: stackoverflow.com



Set branch upstream

# If you create new branch:

git checkout -b branch1 origin/branch1

# you have to set upstream branch during push:

git push -u origin HEAD

git branch -u origin/branch1 branch1

git push origin refs/heads/branch1:branch1 --set-upstream

git push origin refs/heads/branch1:branch1 -u

# updates git project config as :

branch.branch1.remote

branch.branch1.merge

# Config branch:

git config branch.master.remote origin

git config branch.master.merge refs/heads/master



Remote origin (add show update)

git remote add origin https://github.com/user/project.git

git remote show origin

git remote update

Set remote URL (https or ssh)

git remote set-url origin https://github.com/username/project.git

git remote set-url origin git@github.com/username/project.git

# Check remote URLs

git remote -v

origin  https://github.com/username/project.git (fetch)

origin  https://github.com/username/project.git (push)

# Show Git remote URL

git config --get remote.origin.url



Parent branch - merge base

git merge-base branch2 branch3

git merge-base origin/main branch1

git reset $(git merge-base master $(git branch --show-current))

git show --summary `git merge-base foo master` # when was branch created

git log --first-parent



Git commands workflow

HEAD working tree, index, staging area:

Workspace is the directory tree of (source) files that you see and edit.

Index is a single, large, binary file in <baseOfRepo>/.git/index, which lists all files in the current branch, their sha1 checksums, time stamps and the file name -- it is not another directory with a copy of files in it.

Local repository is a hidden directory (.git) including an objects directory containing all versions of every file in the repo (local branches and copies of remote branches) as a compressed "blob" file.

src: stackoverflow

See: Git Branch, HEAD, Refs

See index, commit, repo



Git config - initial setup

https://git-scm.com/book/en/v2/Getting-Started-First-Time-Git-Setup

*

git config --global user.name 'Jon Doe'

git config --global user.email 'jon.doe@github.com'

git config --global core.editor emacs

git config --global core.editor vim

git config --global core.editor "'C:/Program Files/Notepad++/notepad++.exe' -multiInst -notabbar -nosession -noPlugin"

git config --global init.defaultBranch main

*

git config -l

git config --list [--local | --global | --system]

Git config - which config

git config --show-origin --list # show config origin

*

Git config - files

# source:

[path]/etc/gitconfig # system

~/.gitconfig or ~/.config/git/config # global

.git/config # repository



Git alias

git config --global alias.alias "!""git config -l | grep ^alias\\."

git config --global alias.configure "!""vi ~/.gitconfig"

src:

Atlassian aliases

Most useful aliases



CRLF:

git config core.autocrlf true

git config core.autocrlf false

git config core.autocrlf input

# src: stackoverflow.com



Different Git configs

git config --list                              # local: /.git/config - repo-specific

git config --global --list # global: /.gitconfig - user-specific

git config --system --list # system: $(prefix)/etc/gitconfig - system-wide

git config --global --edit # edit



Global proxy settings

git config --global http.proxy myproxy.com:8080


Global SSL verify

git config --global http.sslVerify "false"

git config --global --unset http.sslVerify


Project specific SSL verify

cd C:\git\my-project

git config http.sslVerify "false"

:: git config --unset http.sslVerify



Git template dir:

# ~/.config/git/config or ~/.gitconfig

[init]

    templateDir = ~/.config/git/template/



Relative Refs

# display the grandparent of HEAD:

git show HEAD~2

merge commits => more complicated

merge commints => more parents => more paths to follow


i.e. 3-way merge:

1. parent == main branch you merged into

2. parent == branch mentioned in git merge branchName

~ = follow first parent of merge commit

^ = follow different parent


i.e.: if HEAD is merge commit, display second parent of HEAD by:

git show HEAD^2


Combine into:

git show HEAD^2^1

it is: grandparent of HEAD (if merge commit) which is on the second parent.


Examples:

# Only list commits that are parent of the second parent of a merge commit

git log HEAD^2


# Remove the last 3 commits from the current branch

git reset HEAD~3


# Interactively rebase the last 3 commits on the current branch

git rebase -i HEAD~3


# get back before you ran git reset

git checkout HEAD@{1}

src: atlassian.com



SSH Keys

ssh-keygen -t rsa -b 4096 -C 'username@github.com'

details: https://stackoverflow.com/a/37075506

files: https://en.wikipedia.org/wiki/Ssh-keygen


Linux SSH Keys registration

cat > ~/.ssh/config <<EOF

Host vs-ssh.visualstudio.com

  IdentityFile ~/.ssh/id_rsa

EOF

cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys




Sources

ProGit Book

Reset Demystified

git branch vs git checkout -b

track remote branch

IntelliJ Idea branches



Cheat sheets

Atlassian git cheat sheet page

GitHub cheat sheet

GitLab cheat sheet

Atlassian git advanced – crossroad

Rebase reset revert log hooks refs reflog