Skip to content

Git

gpg

Telling Git about your signing key

Configure

git config --global user.email "[email protected]"
git config --global user.name "nιcнolaѕ wιlde"
git config credential.helper store
git config --global init.defaultBranch main
git config --global user.signingkey <gpg key fingerprint>
git config --global commit.gpgsign true

Usage

Switching Remote URLs

git remote -v
origin  [email protected]:USERNAME/REPOSITORY.git (fetch)
origin  [email protected]:USERNAME/REPOSITORY.git (push)
git remote set-url origin https://github.com/USERNAME/REPOSITORY.git

Syncing a Fork

# Configuring a remote for a fork if it doesn't already exist
git remote add upstream https://github.com/ORIGINAL_OWNER/ORIGINAL_REPOSITORY.git
git fetch upstream
git checkout main
git merge upstream/main
# Push the changes
git push origin main

Different Path

git -C <path>

Empty Message

git commit --allow-empty-message -m ''

Change a Commit Message

git commit --amend

List Commits

git log

URLs

gh

brew install gh
gh auth login

No Message

git commit --allow-empty-message -a -m ""

Synchronizing a local Git repository with a remote one

git fetch --prune
# https://stackoverflow.com/a/17029936/1061279
git branch -r | awk '{print $1}' | egrep -v -f /dev/fd/0 <(git branch -vv | grep origin) | awk '{print $1}' | xargs git branch -d

Deleting Remote Branch

git branch -d <branch name>
git push origin --delete <branch name>

Rename Branch

git branch -m <new branch name>

Restore a File From Remote

git fetch
git restore -s origin/main -- path/to/file

Reset last commit

git reset --hard HEAD^

Reset last two commits

git reset --hard HEAD~2

Delete Github Tag

git push --delete origin <tag name>

Unstage file that has been added but not commited

git restore --staged <file name>

Get Latest Version

Strips v and release prefixes

curl -sX GET "https://api.github.com/repos/Jackett/Jackett/releases/latest" | jq --raw-output '.tag_name'
version="${version#*v}"
version="${version#*release-}"

Get Latest Commit

Get's the first 7 characters of commit.

curl -sX GET https://api.github.com/repos/seejohnrun/haste-server/commits/master | jq --raw-output '. | .sha'
version="${version#*v}"
version="${version#*release-}"
version="${version:0:7}"

References

Back to top