Skip to content

kr-nn/gitauth

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

gitauth – Simple & Dynamic Authentication

This is a very simple Git credential helper that dynamically selects the correct authentication credentials based on:

  • The remote URL you're pushing to
  • Your configured Git user.email and user.name

How It Works

  1. Git calls this script when authentication is needed.
  2. The script checks:
  • The remote URL you're pushing to.
  • Your configured user.email (highest priority).
  • Your configured user.name (fallback if no email match is found).
  1. It searches ~/.git-credentials for the correct credentials.
  2. If a match is found, it provides the correct username and token for authentication.

This means: ✅ No need to manually switch credentials ✅ Works automatically based on your repo’s Git config or global config ✅ No per-repo configuration required

Installation

Manual

  1. Clone this repo and move the script into your $PATH:
git clone https://github.com/kr-nn/gitauth
cd gitauth
chmod +x gitauth
mv gitauth ~/.local/bin/  # Or /usr/local/bin/

nix

nix shell github:kr-nn/gitauth

or

nix profile install github:kr-nn/gitauth

or

# flake.nix
{
  inputs.gitauth.url = "github:kr-nn/gitauth";
  ...
  outputs = let
    gitauthPkg = gitauth.packages.${system}.gitauth
    in { ... gitauthPkg, ... } : { ... specialArgs = { gitauthPkg }; }
}

...

environment.systemPackages = [ gitauthPkg ];

Configure

  1. Set it as your Git credential helper:
git config --global credential.helper "!gitauth"
  1. Make sure your ~/.git-credentials file contains your stored credentials:
https://user1:ghp_token1@github.com
https://user2:ghp_token2@github.com
https://user1@email.com:ghp_emailtoken1@github.com
https://user2@email.com:ghp_emailtoken2@github.com

!NOTE: do not use %40 in place of @, the script does this for you

  1. Set your user.email or user.name in each repo or globally:
git config user.email "user1@email.com"
git config user.name "user1"

or

git config --global user.email "user1@email.com"
git config --global user.name "user1"

Just push as usual:

git push # or git push origin

The script will automatically select the right token based on your user.email or user.name!

Why Use This?

🔹 Simple: No complex setup, just drop it in and it works.

🔹 Automatic: Picks the right credentials for each repo.

🔹 Portable: Works anywhere, no per-repo config needed.

About

Stupid simple git credential manager

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published