Git
Configuration
Set name and email
git config --global user.name “Your Name”
git config --global user.email "email@example.com"
Setup 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}
Start a project
git init [project_name]
or
git clone [project_url]
Base commands
Show working tree status
git status
Add a file to staging
git add [file]
Remove a file from staging
git reset [file]
Commit
git commit -m "[message]"
Working with the remote repo
Push
git push
# or
git push origin [branchname]
To associate a local branch with the remote
git push -u origin [branchname]
Pull
Note that a pull is actually a fetch and then a merge.
git pull origin [branchname]
Reset to match remote
git reset origin/main
List remote repos
git remote -v
Cleanup
Clean local branches not on remote
git fetch --prune
Stashing
Git stash is really useful if you are working on something and want to come back to it later. This is integrated in lazygit.
git stash
Bring back changes
git stash apply
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