Git

Posted on Dec 3, 2025

Configuration

PurposeCommand
Show all configgit config --list
Show user namegit config --get user.name
Show user emailgit config --get user.email
Set global namegit config --global user.name "Your Name"
Set global emailgit config --global user.email "[email protected]"
Set local namegit config user.name "Your Name"
Unset global emailgit config --global --unset user.email
Check working tree statusgit status
Disable core editor promptsgit config core.editor true
Set a core editorgit config core.editor "nano"

Remotes & Authentication

GitHub no longer allows password-based authentication. Use a Personal Access Token (PAT).

Profile > Settings > Developer settings > PAT > Fine-grained tokens

Required permissions: Read access to metadata, Read and Write access to code

PurposeCommand
Clone a projectgit clone <project-url>
List remotesgit remote -v
Update remote (HTTPS + PAT)git remote set-url origin https://<user>:<PAT>@github.com/<user>/<repo>.git
Switch to SSHgit remote set-url origin [email protected]:<user>/<repo>.git

GPG keys

PurposeCommand
Install GNUPGsudo apt install gnupg
Generate key (RSA and RSA)gpg --full-generate-key
View the keysgpg --list-secret-keys --keyid-format=long
Export the Public Keygpg --armor --export <gpg-key-id>
Set key to repogit config user.signingkey <gpg-key-id>
Sign commitsgit config commit.gpgsign true
Sign tagsgit config tag.gpgsign true

After viewing the keys, sec rsa4096/xxxxxxxxxxxxxxxx the x part is the gpg-key-id. The long exported public key is pasted in Github → Settings → SSH and GPG Keys. Once done, go to git config list and verify.

Branches

PurposeCommand
List local branchesgit branch
List remote branchesgit branch -r
Push branch to origingit push origin <branch>
Pull branch from origingit pull origin <branch>

Commits

PurposeCommand
Add filesgit add <filename>
Add multiple filesgit add .
Commit with messagegit commit -m "message"
Commit and close issue Keywordsgit commit -m "message (closes #issue)"
Commit & close multiple issuesgit commit -m "message (closes #issue, closes #issue)"
Verify commit authorgit log --pretty=full

Commitizen

For a standardized way to commit messages and bump versions, use commitizen.

PurposeCommand
Initialize commitizencz init
Commitcz commit
Release a version (auto decides based on commits)cz bump
Release a patchcz bump --increment patch
Release a minorcz bump --increment minor
Pre-release a versioncz bump --prerelease rc
Push branch + annotated tags on pushed commitsgit push origin <branch> --follow-tags
Push branch + all local tagsgit push origin <branch> --tags
Push branch + specific tag(s)git push origin <branch> v0.0.0

Cleanup

PurposeCommand
Prune deleted remote branchesgit fetch -p
Delete local branchgit branch -D <branch>
Delete multiple branchesgit branch -D <b1> <b2> <b3>

Transfer

Transfer an existing project from Gitlab to Github. Clone the existing repo locally. Create a new clean Github repo. On the Gitlab project,

PurposeCommand
Add Github urlgit remote add <url>
Push to Githubgit push github --all

Tags and Logs

PurposeCommand
Manual taggit tag -a v0.5.0 -m "Release v0.5.0"
List all tagsgit tag --list
Show tags with commitsgit show-ref --tags
Last loggit log -1 --oneline