I use git quite a lot and despite the good documentation, it's nice to have some things at hand

Posted August 11, 2022 by Adrian Wyssmann

This page lists a collection of interesting git commands


Some good resources


Purpose Command
Reset to a specific commit-hash git reset --hard <commit-hash>
git push -f origin master
Reset to inital commit git update-ref -d HEAD
Reset local branch to status from remote git reset --hard <remote>/<branch>
Check out the fb branch, and rebase from master git checkout fb
git rebase master
Branches: delete a local branch1 git branch -d BRANCH_NAME
Branches: delete a remote branch1 git push --delete origin BRANCH_NAME
Branches: delete all branches on remote that are already merged1 git branch --merged | egrep -v "(main|master|dev)" | xargs git branch -d
Tags: tag a commit git tag -a <tag> <commit> -m "<commit message>"
Tags: delete a tag on remote git push --delete origin [TAGNAME]
Tags: delete a tag locally git tag -d [TAGNAME]
Change author of a commit git commit --amend --author="Author Name <[email protected]>"
The GPG key used for signing your commits git config --global user.signingkey 0A46826A
Sign new tags git tag -s v1.5 -m 'my signed 1.5 tag'
Sign a commit git commit -a -S -m 'Signed commit'
check any signatures it finds and list them in its output git log --pretty="format:%h %G? %aN %s"
Defined the key to use for signing commits git config user.signingkey [KEYID]
Set signing of commits globally git config --global commit.gpgsign true

Useful One-liners

GET-DATE -Format o | Out-File .\; git add .\; git commit -m "Test"; git push

Remove credentials from git

git config --global --unset credential.helper
git config --system --unset credential.helper
git config --global credential.helper manager

Edit this page