git

init submodules

git submodule update --init --recursive

adding keys

  1. Generate the key

    ssh-keygen -t rsa -b 4096 -C your_email@example.com

  2. Copy the key to clipboard

    clip < ~/.ssh/id_rsa.pub

  3. Start agent

    eval $(ssh-agent -s)

  4. Add key to agent ssh-add ~/.ssh/id_rsa

integrate beyond compare

# diff
git config --global diff.tool bc3
# merge
git config --global merge.tool bc3
git config --global mergetool.bc3.trustExitCode true

find your missing commit

git reflog

commit messages

A note about git commit messages

set user and email

git config --global user.name "Firstname Lastname"
git config --global user.email "email@domain.com"

reviewing a merge commit locally

git config --add remote.origin.fetch +refs/pull/*/merge:refs/remotes/origin/pr/*
git fetch origin
git checkout pr/1234

More on richard-banks.org

integrate beyond compare in wsl

Inside ~/.gitconfig:

[diff]
        tool = bcomp
[difftool]
        prompt = false
[difftool "bcomp"]
        path = "/mnt/c/Program\\ Files/Beyond\\ Compare\\ 4/BCompare.exe"
        cmd = "/mnt/c/Program\\ Files/Beyond\\ Compare\\ 4/BCompare.exe" "$(wslpath -aw $LOCAL)" "$(wslpath -aw $REMOTE)"
[merge]
        tool = bcomp
[mergetool]
        prompt = false
[mergetool "bcomp"]
        path = "/mnt/c/Program\\ Files/Beyond\\ Compare\\ 4/BCompare.exe"
        cmd = "/mnt/c/Program\\ Files/Beyond\\ Compare\\ 4/BCompare.exe" "$(wslpath -aw $LOCAL)" "$(wslpath -aw $REMOTE)" "$(wslpath -aw $BASE)" "$(wslpath -aw $MERGED)"

list contributors

git shortlog -s -n --no-merges

set upstream branch automatically

git config --global push.default current

Now you can git push a new branch without needing to git push -u some-branch

aliases

git config --global alias.co checkout
git config --global alias.branches branch --sort=-committerdate

updating

ubuntu

sudo add-apt-repository ppa:git-core/ppa
sudo apt update
sudo apt-get install git

windows

git update-git-for-windows

macOS

brew install git

configure windows ssh

  1. Set service OpenSSH Authentication Agent to Automatic and Start it.
  2. In Powershell, ssh-add
  3. In environment variables, add GIT_SSH=C:\Windows\System32\OpenSSH\ssh.exe

See more

backup github repos

Backup personal github repos

docker run -it -v ${PWD}:/out python:3 bash
pip install git+https://github.com/clockfort/GitHub-Backup
chmod +x /usr/local/lib/python3.11/site-packages/github_backup/github_backup.py
/usr/local/lib/python3.11/site-packages/github_backup/github_backup.py staff0rd /out/backup -p YOUR_PAT -t http

More info