How to use the git-credential-bw tool so that Git automatically retrieves your credentials from Bitwarden. This avoids manually entering your password for every Git operation requiring authentication.
Before starting, make sure you have:
- Bitwarden CLI is a command-line tool to access your Bitwarden vault.
- To install and configure it, follow the official guide: Bitwarden CLI Documentation
- To check, type in a terminal:
git --version- If not installed, see git
Open a terminal and run:
curl -o $HOME/.local/bin/git-credential-bw https://github.com/tsenay/git-credential-bw/raw/main/git-credential-bw- This command downloads the script into
$HOME/.local/bin, which is usually included in yourPATH. If the folder does not exist, create it:
mkdir -p $HOME/.local/binchmod +x $HOME/.local/bin/git-credential-bwCheck:
echo $PATHIf not, add it to your ~/.bashrc or ~/.zshrc:
export PATH="$HOME/.local/bin:$PATH"Then reload:
source ~/.bashrc- Log in to your Bitwarden vault (via app or website).
- Create a new Login entry for each Git server (e.g.,
gitlab.com,github.com).- Item name: Git server hostname (e.g.,
gitlab.com) - Username: your Git username
- Password: your Git password or personal access token
- Item name: Git server hostname (e.g.,
Set credential helper for your git server
git config --global credential."https://gitlab.com".helper bw- Replace
gitlab.comwith your Git server name if needed. - This tells Git to use the
git-credential-bwscript to retrieve credentials.
- When performing a Git operation requiring authentication (e.g.,
git clone,git push), Git will call the script, which fetches credentials from Bitwarden. - If you are not logged in via CLI, you will be prompted:
bw login
bw unlock- For security, lock your Bitwarden vault after use:
bw lock- To list all vault entries:
bw list items