Git and Github

roman-synkevych-wX2L8L-fGeA-unsplash

Installing gh

Notice: this might change, go here

type -p curl >/dev/null || sudo apt install curl -y
curl -fsSL https://cli.github.com/packages/githubcli-archive-keyring.gpg | sudo dd of=/usr/share/keyrings/githubcli-archive-keyring.gpg \
&& sudo chmod go+r /usr/share/keyrings/githubcli-archive-keyring.gpg \
&& echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/githubcli-archive-keyring.gpg] https://cli.github.com/packages stable main" | sudo tee /etc/apt/sources.list.d/github-cli.list > /dev/null \
&& sudo apt update \
&& sudo apt install gh -y

Authenticate

gh auth login

Setup Git

# 8280770+
git config --global user.name Azat
git config --global user.email [email protected]

gh auth setup-git

Git Branching

image-20230519162239287

Overall Sequence Digram

main->dev: git checkout -b dev main
# feature
dev->feature: git checkout -b feat-xxx dev
feature-->dev: git checkout dev
feature-->dev: git merge --no-ff feat-xxx
Note right of feature: git branch -d feat-xxx

# release
dev->release: git checkout -b rc-1.2 dev
Note right of release: ./fix-version.sh 1.2
Note right of release: git commit -m "version fixed for release: 1.2"
release-->main: git checkout main
release-->main: git merge --no-ff rc-1.2 
release-->main: git tag -a 1.2 
release-->dev: git checkout dev
release-->dev: git merge --no-ff rc-1.2 
Note right of release: git branch -d rc-1.2

# hotfix
main->hotfix: git checkout -b fix-1.2.1 dev
Note right of hotfix: ./fix-version.sh 1.2.1
Note right of hotfix: git commit -m "version fixed for release: 1.2.1"
Note right of hotfix: git commit -m "fixed severe production bug #12134"
hotfix-->main: git checkout main
hotfix-->main: git merge --no-ff fix-1.2.1
hotfix-->main: git tag -a 1.2.1 
hotfix-->dev: git checkout dev
hotfix-->dev: git merge --no-ff fix-1.2.1
Note right of hotfix: git branch -d fix-1.2.1

2023-05-19-at-16.01.20

Origin

git push origin xxxx
git push internal xxxx
git push bitbucket xxxx
git push public xxxx

Main branches : main, dev

git checkout -b dev main

Supporting branches

Feature

graph LR 
D[dev] -->|1-checkout| F[feature] -->|2-merge| D1[dev]
# creating a feature branch
git checkout -b feat-xxx dev
# WORK
# incorporating a finished feature on develop
git checkout dev 
git merge --no-ff feat-xxx
git branch -d feat-xxx
git push origin dev

Release

graph LR 
D[dev] -->|1-checkout| R[release]
R -->|2-merge| M[main]
R -->|2-merge| D1[dev]
# creating a release branch
git checkout -b rc-1.2 dev
# WORK
# freeze versions and build numbers in the files
./fix-version.sh 1.2
# commit
git commit -a -m "version fixed for release: 1.2"

# finishing a release branch and merge to main
git checkout main 
git merge --no-ff rc-1.2 
git tag -a 1.2

# to keep the changes made in the release branch, we need to merge those back into develop
git checkout dev
git merge -no-ff rc-1.2

# end of release-xxx
git branch -d rc-1.2

Hotfixes

graph LR 
M[main] -->|1-checkout| H[hotfix]
H -->|2-merge| M1[main]
H -->|2-merge| D1[dev]
# create the hotfix branch
git checkout -b fix-1.2.1 main
./fix-version.sh 1.2.1 
git commit -m 'version fixed at 1.2.1'
# fix the bug now
# WORK
# after bug fixed
git commit -m 'fixed severe production bug #12134'

# finishing a hot fix branch
git checkout main
git merge --no-ff fix-1.2.1
git tag -a 1.2.1

# also need to merge to dev
git checkout dev
git merge --no-ff fix-1.2.1

# life end of fix
git branch -d fix-1.2.1