GIT
Submodules
git submodule update --recursive --init
Reset history of a repo
git checkout --orphan newBranch
git add -A
git commit
git branch -D master
git branch -m master
git push -f origin master
git gc --aggressive --prune=all
See public ssh keys
https://github.com/USERNAME.keys
https://gitlab.com/USERNAME.keys
GIT config
git config --list --global
git config --global user.name "n4n5"
Commits stats
git shortlog -sn
pre-commit
python -m pip install -u pre-commit
python -m pre_commit install
python -m pre_commit run --all-files
Add multiple push URLs
git remote set-url --add --push [remote] [original_repo_URL]
git remote set-url --add --push [remote] [second_repo_URL]
git remote -v
Change commit date
changeCommitDate() {
VARIABLE="${1:-3}"
printf 'DAT=$(date --date "%s days ago" -R) GIT_AUTHOR_DATE=$DAT GIT_COMMITTER_DATE=$DAT git commit -m "message"\n' "$VARIABLE"
}
Useful git commands
git add -p
git commit -v
git push --force-with-lease
https://dimtion.fr/blog/average-engineer-tips/
Rebase
GIT_EDITOR=vi git rebase -i HEAD~10
Find big object
git rev-list --objects --all \
| git cat-file --batch-check='%(objecttype) %(objectname) %(objectsize) %(rest)' \
| sed -n 's/^blob //p' \
| sort --numeric-sort --key=2 \
| tail -n 10 \
| cut -c 1-12,41- \
| $(command -v gnumfmt || echo numfmt) --field=2 --to=iec-i --suffix=B --padding=7 --round=nearest
git log --all --find-object=OBJECTID
https://stackoverflow.com/a/46085465
Fetch repository on different remote
git fetch -u https://codeberg.org/org/repo master:master-local
git switch master-local