Git

start using git

git init

check status

git status

show all difference since last commit

git diff

git clone without downloading

git clone <repo> --no-checkout

commit with message

git commit -m "<msg>"

stage all changes and commit

git commit -am "<msg>"

revert to the last commit

git reset HEAD~

or

git revert …

change the last commit

--amend

add repo as submodule

git submodule add <repo>

push book folder to GitHub gh-pages to publish pages

git subtree push --prefix book origin gh-pages

push all branch to all remote

git remote | xargs -L1 git push --all

push master to all remote

git remote | xargs -L1 -I R git push R master

pull every repo under the current folder

fd .git -H -t d -x git --git-dir={} pull

fetch and status every repo under the current folder

fd .git -H -t d -x git --git-dir={} fetch \; -x git --git-dir={} --work-tree {}/.. status

delete all history of a certain file (deprecated)

FILTER_BRANCH_SQUELCH_WARNING=1 git filter-branch --index-filter \
    'git rm -rf --cached --ignore-unmatch <path_to_file>' HEAD

delete all history of a certain file using git-filter-repo

git filter-repo --invert-paths --path '<path_to_file>' --use-base-name

ignore all symlink

find * -type l -not -exec grep -q "^{}$" .gitignore \; -print >> .gitignore

check what are the branches

git fetch && git branch

check out another branch

git checkout <branch>

create orphan branch

git switch --orphan <branch>

force sync from origin

git reset --hard origin/master

git commit sizes

bash -c "git rev-list --objects --all |
git cat-file --batch-check='%(objecttype) %(objectname) %(objectsize) %(rest)' |
sed -n 's/^blob //p' |
sort --numeric-sort --key=2 |
cut -c 1-12,41- |
$(command -v gnumfmt || echo numfmt) --field=2 --to=iec-i --suffix=B --padding=7 --round=nearest"

verify no change since commit

git diff --exit-code HEAD

pull main without checking out main

git fetch origin main:main

fetch only 1 commit

git fetch --depth 1 git@github.com:username/repo.git FULL_SHA_FOR_COMMIT

remove uncommitted files

git clean -f

remove ignored files

git clean -fX