Git
upcoming: - cherry-picking - force-with-lease - squash
Basics
initialize empty git repo
git init <repo-name>
push repo to remote:
clone repo locally
git clone <repo-url>
configuration
repository status
git status
specific filechanges
git diff <file-name>
get quick overview of last repo change
git log --oneline
undo changes
git revert <git-hash>
add file to staging area
git add <filename>
commit changes to repo
git commit -m '<commit-message>'
push changes to remote server
git push
get latest changes from remote
git pull
ignore files and dirs by adding their relative paths to the following file
.gitignore
Branching
create new branch
git checkout -B '<new-branch-name>'
delete branch
git branch -D '<branch-to-delete>'
upcoming: rebase
Inspect recent changes
e.g. for the src dir,
git whatchanged --since="last Sunday" -p -- src
Fixing detached HEAD, when on feature branch
Remove all git history from repo
#!/usr/local/bin/bash
# prerequisites:
# all tags deleted
# main branch is the only branch that exists
: '
git checkout --orphan last
git add -A
git commit -am "feat: rewrite git history" --no-verify
git branch -D main
git branch -m main
git push -f origin main -v
cd .git
git reflog expire --expire=now --all && git gc --prune=now --aggressive
# check size:
du -hs .
du -hs .git
'