Git

Git - Mass Updater

Intro

Let’s assume you have a bunch of GIT Repos in a Folder like this:

/project1/
    /repo1/
    /repo2/
    /repoN/

and you would like to update all of them ? here a little helper.

  • Loop over all Folders
  • check if ‘.git’ exists
  • if so, do a git pull –all

Script

Copy/Paste it to your Terminal and you get a executable Script called ‘git_update_all.sh’.

cat << 'EOF' > git_update_all.sh
#!/usr/bin/env bash

# Get the current script directory
script_dir=$(dirname "$(readlink -f "$0")")

# Change into each directory in the script folder
for dir in "$script_dir"/*; do

    if [ -d "$dir" ]; then

        cd "$dir" || exit 1

        if [ -d ".git" ]; then

            echo "Updating Git repository in $dir"
            git pull --all

        else

            echo "Skipping $dir - not a Git repository"

        fi

        cd "$script_dir" || exit 1

    fi

done

echo "Git update for all repositories completed."
EOF

# make it executable
chmod u+x git_update_all.sh

Usage

and then run it, like it, use it :)

Git Tags

With Tags, we have the possibility to “Tag” a certain Point as important. Just give it a release Number (v0.1, v0.2, v1.0) or whatever you like.

list tags

list all tags for a certain repo

git tag

add Tag

when you’re fine with a version, add a tag …

git tag -a v1.0 -m "my Version 1.0"

push Tags

you have to push the Tags separatly. they do not get pushed with the common “git push” command

Oneliners

Misc Oneliners

Tar Folder and copy to remote Machine

tar cf - /etc/ |ssh ${remote-host} "cd /tmp/ && cat > $(hostname)-etc.tar"

Tar & GZIP Folder and copy to remote Machine

tar czf - /etc/ |ssh ${remote-host} "cd /tmp/ && cat > $(hostname)-etc.tar.gz"

Dump Certs Chain

s="google.com"; timeout 2 openssl s_client -servername ${s} -connect ${s}:443 -showcerts > /tmp/${s}.chain

selfsigned certificate for 1 year

cd /etc/ssl; openssl req -nodes -x509 -newkey rsa:4096 -keyout key.pem -out cert.pem -days 356

set default branch to main

git config --global init.defaultBranch main

bash - check multiple files

[ -f /etc/resolv.conf -a -f /etc/hosts ] && echo "Both files exist" || echo "One or Both Files are missing"

remove word ’nosuid’ on the line /var in /etc/fstab

sed -E -i.bak 's/(.*\/var.*)(,nosuid)(.*)/\1\3/' /etc/fstab

macos show hidden files

defaults write com.apple.finder AppleShowAllFiles -boolean true; killall Finder

or

Git aliases

we all do like aliases, right ?

https://git-scm.com/book/en/v2/Git-Basics-Git-Aliases

Some Aliases

git config --global alias.co checkout
git config --global alias.br branch
git config --global alias.ci commit
git config --global alias.st status
git config --global alias.bra "branch -a"

and then, you just type:

git co
git br
git ci
git st
git bra

.gitconfig

all this stuff is saved in ~/.gitconfig

$ cat ~/gitconfig
# This is Git's per-user configuration file.
...
[alias]
  co = checkout
  br = branch
  ci = commit
  st = status
  bra = branch -a

Any Comments ?

sha256: 1175e6dde38a2eaed638973cbcd44b5d877ef48acc4e42127dbed167ec15cd1c

Git Branches

Branches

some basic commands for branches. you can read Branch Basics and Branch Management for more details

create branch

you wanna develope a feature, fix a bug, test some stuff … you need a branch !

git checkout -b feature1

push upstream

if you have a central repo, push the feature upstream (so others can checkout as well)

git push --set-upstream origin feature1

show branch

you may have multiple branches, list them all. and update pager so list will not open in VIM !

Git Clear your History

Clear History

have you ever checked in some binarys, confidential stuff or something else by mistake ? Git will keep all your history, that’s their design and purpose.

how ever, if you need to cleanup once, here is a short tutorial.

Kill Git Config

cd myrepo
cat .git/config -> note down the url
url=$(git config --get remote.origin.url)
rm -rf .git

Create New Repo

git init
git add .
git commit -m "Removed history, ..."

Push Remote

git remote add origin git@host/yourrepo  <- URL you noted down above
git remote add origin $url
git push -u --force origin master

All in One

_url=$(git remote -v |awk '/fetch/ { print $2 }')
rm -rf .git
git init
git add .
git commit -m "Removed history ..."
git remote add origin ${_url}
git push -u --force origin main
unset _url

and you’re done :)

GIT add Folder to Repo

wanna switch a local folder to a remote git repo ?

https://docs.github.com/en/github/using-git/adding-a-remote

GitoLite

create git repo with gitolite (myproject)

add Folder

cd myproject

git init
git remote add origin git@your-git-server:myproject

check Status

git remote -v
git status

add all existing Files, commit and push to remote

git add .
git commit -m "initial commit"
git push --set-upstream origin master

Any Comments ?

sha256: ba5ff311face100add7e9b21efbbb86af94545d3aec2cf8d920ea55ba5353464

Gitolite

You wanna host your own Git Repositories ? Have a look at Gitolite. It does all for you :)

Install GitoLite

pkg_add gitolite

Add git user

root@gitserver ~# adduser -silent
Enter username []: git
Enter full name []: git repo user
Enter shell bash csh git-shell ksh nologin sh [ksh]:
Uid [1001]:
Login group git [git]:
Login group is ``git''. Invite git into other groups: guest no
[no]:
Login class authpf bgpd daemon default pbuild staff unbound
[default]:
Enter password []:
Disable password logins for the user? (y/n) [n]: y

Name:        git
Password:    ****
Fullname:    git repo user
Uid:         1001
Gid:         1001 (git)
Groups:      git
Login Class: default
HOME:        /home/git
Shell:       /bin/ksh
OK? (y/n) [y]: y
Added user ``git''
Add another user? (y/n) [y]: n

Basic Setup

Setup Repo, add your key

Git

Some Git Commands

Customizing Git

Switch from “Master” to Main globally

git config --global init.defaultBranch main

Merge two Repos “merge unrelated histories”

git pull origin master --allow-unrelated-histories
git push
git pull

add local Folder and Push to Upstream

echo "# test" >> README.md
git init
git config init.defaultBranch main
git add README.md
git commit -m "first commit"
git branch -M main
git remote add origin [email protected]:stoege/test.git
git push -u origin main

Find deleted file, sort uniq

git log --all --pretty=format: --name-only --diff-filter=D | sort -u
bla
bla.yml
doit.sh
files.conf.j2
...

Find deleted File

git log --diff-filter=D --summary

commit abcecadce91af3814662fa6a04d0f12e361f0574
Date:   Sun May 31 23:19:59 2020 +0200

    update

 delete mode 100644 master/sed.tcpdump

commit 81ae58d70c27d02eb2f65beed4fe0b571073f087
Date:   Fri May 29 16:06:14 2020 +0200

    update

Restore deleted File

git checkout 81ae58d70c27d02eb2f65beed4fe0b571073f087 sed.tcpdump

Remove Sensitive Data

git filter-branch --force --index-filter \
'git rm --cached --ignore-unmatch .geheimesfile' \
--prune-empty --tag-name-filter cat -- --all

git push origin --force --all

git push origin --force --tags

Remove last Commit

will remove the last Commit from your current branch

SSH Audit

ssh-audit is a tool for ssh server auditing.

Features

SSH1 and SSH2 protocol server support;

grab banner, recognize device or software and operating system, detect compression;

gather key-exchange, host-key, encryption and message authentication code algorithms;

output algorithm information (available since, removed/disabled, unsafe/weak/legacy, etc);

output algorithm recommendations (append or remove based on recognized software version);

output security information (related issues, assigned CVE list, etc);

analyze SSH version compatibility based on algorithm information;