Git

Cheatsheet

Base commands

To add changed files to staging

git add <filename>

To check the status of files that have been added to staging

git status

To push changes to a remote repository

git push

Merging

Update a fork with changes from the upstream repository

git remote add upstream https://codeberg.org/whoever/whatever.git
git fetch upstream
git checkout main
git rebase upstream/main

Merge two local repositories

cd path/to/project-a
git checkout some-branch

cd path/to/project-b
git remote add project-a /path/to/project-a
git fetch project-a --tags
git merge --allow-unrelated-histories project-a/some-branch
git remote remove project-a

Sign commits with a gpg key

List current keys

gpg --list-secret-keys --keyid-format=long

Copy the keyid

Tell git about the key to use

git config --global user.signingkey {keyid}

Git Stash

Git stash is really useful if you are working on something and want to come back to it later. This is intigrated in lazygit.

Stash changes

git stash

Bring back changes

git stash apply