git

Gitea

Install as Docker container
http://www.panticz.de/docker/container/gitea

APT packages
https://gitlab.com/packaging/gitea

Download archive
https://dl.gitea.io/gitea/

Migrate from gogs
https://docs.gitea.io/en-us/upgrade-from-gogs/

Backup
https://docs.gitea.io/en-us/backup-and-restore/

Install gitea on Kubernetes
https://docs.gitea.com/installation/install-on-kubernetes

helm repo add gitea-charts https://dl.gitea.com/charts/
helm install gitea gitea-charts/gitea

Links
https://gitea.io/

GitLab runner

Install
wget https://packages.gitlab.com/runner/gitlab-runner/gpgkey -O - | apt-key add -
cat < /etc/apt/sources.list.d/gitlab-runner.list
deb https://packages.gitlab.com/runner/gitlab-runner/ubuntu/ xenial main
EOF
apt update
apt install gitlab-runner

Instlal with Ansible
https://github.com/panticz/ansible/tree/master/roles/gitlab-runner
https://github.com/haroldb/ansible-gitlab-runner

Get token from GitLab server
http:///admin/runners

# configure DNS for GitLab server

gogs

apt -y install docker-compose

cat < docker-compose.yml
version: "2"

networks:
gitea:
external: false

services:
web:
image: gitea/gitea:latest
environment:
- USER_UID=1000
- USER_GID=1000
- DB_TYPE=mysql
- DB_HOST=db:3306
- DB_NAME=gitea
- DB_USER=gitea
- DB_PASSWD=gitea
restart: always
networks:
- gitea
volumes:
- ./gitea:/data
ports:
- "80:3000"
- "222:22"
depends_on:
- db
db:
image: mysql:latest
restart: always
environment:

GitLab: Web-based Git repository manager

Install
http://www.panticz.de/install-gitlab

# restart gitlab
gitlab-ctl restart

# git home directory
/var/opt/gitlab

Reset admin password
# change root password
sudo gitlab-rails console
user = User.where(id: 1).first
user.password = user.password_confirmation ='xxx'
user.save!

Gitlab settings API
https://docs.gitlab.com/ee/api/settings.html
curl --header "PRIVATE-TOKEN: 11112222333344445555" https://gitlab.example.com/api/v4/application/settings

Disalbe register / Singup

Git

git hooks post-merge example
<?php
$URL="https://raw.githubusercontent.com/panticz/scripts/master/git/post-merge";
echo "

";
$c = curl_init();
curl_setopt($c, CURLOPT_URL, $URL);
curl_setopt($c, CURLOPT_RETURNTRANSFER, 1);
echo htmlspecialchars(curl_exec($c));
curl_close($c);
echo "

";
?>

# show repository info
git describe
git config -l

# show commit info
git show

# show diff for one file
git diff

# commit only one file
git commit -m 'my comment' path/to/file

# create Git repository
git init

# add all files
git add .

# commit
git commit -m "initial project version"

# list tag
git tag -l

checkout
# checkout over SSH
git clone git@github.com:foo/bar.git

# pull single file
git checkout filename

# pull single file from remote
git checkout origin/master -- path/to/file
# pull all files from remote
git checkout origin/dev -- .

# sync changes from other branch
git rebase master
git rebase brach1

# checkout to checkout to specific folder
git clone https://github.com/panticz/installit.git /path/to/folder

# create tag
git tag -a v1.4 -m 'version 1.4'
git push --tags
git push origin

# remove tag
git tag -d tag123
git push origin :refs/tags/tag123

# checkout tag
git clone --branch bar-1.0.4 git@git.example.com:foo/ansible.git /tmp/bar-1.0.4

# git pull single file
git checkout origin/master -- file_name

# checkout commit
git checkout commit_hash

Branch
# reset branch
git reset --hard origin/master
git reset --hard origin/branch123
git reset --hard

# rollback to revision
git checkout 96fe40ded8277725d244aac83c42256ad554cc3b .

# create branch
git checkout -b branch_name

# switch branch
git checkout branch_name
git checkout master

# checkout branch
git clone --branch --single-branch []

# diff all files betwen braches
git diff dev..stage

# diff singe file between branches
git diff dev..stage file1

# diff branches and show file name only
git diff --name-only dev..stage

# diff differnet fiels in different branches
git diff branch1:file branch2:file

# test
git reset file/to/overwrite

# search for string
git grep "string/regexp" $(git rev-list --all)

# grep
git grep foo HEAD

# remove last commit
git reset HEAD~1

# reset to latest revision
git reset --hard

# reset to commit-id
git reset --hard
git push origin HEAD --force

git cherry-pick commit1

branch
# diff between branches
git diff master

# show branches
git branch

# push local Git branch to remote master branch
git push origin local_branch_1:master

# delete local branch
git branch -d local_branch_name

# delete remote branch
git push origin :remote_branch_name

# delete directory / file from git repository without removing from disk
git rm --cached -r DIR1

# ignore
./.gitignore

# git global setup
git config --global user.name "first_name last_name"
git config --global user.email "user@example.com"
git config --global core.autocrlf true

# create a new repository
git clone git@example.com:repository_group/repository_name.git
cd repository_name
touch README.md
git add README.md
git commit -m "add README"
git push -u origin master

# Add existing folder or Git repository
cd existing_folder
git init
git remote add origin git@example.com:repository_group/repository_name.git
git add .
git commit
git push -u origin master

# search for string in commit
git grep foo $(git rev-list --all)

# check out single file
git archive --remote=git@git.example.com:foo/bar.git HEAD:path1/file_or_dir target_file_name | tar --extract

# set proxy
http://cms-sw.github.io/tutorial-proxy.html
git config --global http.proxy $http_proxy
git config --global https.proxy $https_proxy

# undo changes on file
git checkout -- file

# inclue a commit
git cherry-pick commit1

http.sslVerify
http.sslCAInfo
http.sslCAPath
http.sslCert
http.sslKey
http.sslCertPasswordProtected

# pass GIT settings over SSH
https://cweiske.de/tagebuch/carry-git-settings.htm
GIT_SSH_COMMAND="ssh -i ~/.ssh/id_rsa_example -F /dev/null" git clone example
git config core.sshCommand "ssh -i ~/.ssh/id_rsa_example -F /dev/null"

Submodule
https://chrisjean.com/git-submodules-adding-using-removing-and-updating/
git rm --cached roles/icinga-client
git submodule add git@git.example.com:foo/ansible-roles/icinga-client.git roles/icinga-client

# update submodule
git submodule update --recursive --remote

Install GitLab

<?php
$URL="https://raw.githubusercontent.com/panticz/installit/master/install.gitlab.sh";
echo "wget -q --no-check-certificate $URL -O - | bash -";
echo "

";
$c = curl_init();
curl_setopt($c, CURLOPT_URL, $URL);
curl_setopt($c, CURLOPT_RETURNTRANSFER, 1);
echo htmlspecialchars(curl_exec($c));
curl_close($c);
echo "

";
?>

HowTo
http://www.panticz.de/gitlab

Login
http://YOUR_SERVER_IP
user: root
pass: 5iveL!fe

Downloads: GitLab CE Download Archives
https://about.gitlab.com/downloads/archives/

# check instalation
gitlab-rake gitlab:check

# GitLab APT repository
https://packages.gitlab.com/gitlab/gitlab-ce

# rebuild an authorized_keys file
gitlab-rake gitlab:shell:setup

# install specific version
sudo apt-get install -y gitlab-ce=7.10.1~omnibus.1-1

Send email notification
Notify.test_email('foo@example.com', 'GitLab test subject', 'GitLab test message').deliver_now

Links
https://packages.gitlab.com/gitlab/gitlab-ce/install
https://packages.gitlab.com/gitlab/gitlab-ce/
https://about.gitlab.com/downloads/
https://gitlab.com/gitlab-org/omnibus-gitlab/blob/master/README.md#installation
https://www.gitlab.com/2014/02/14/gitlab-is-now-simple-to-install/
https://about.gitlab.com/downloads/archives/ - old GitLab packages archive