Skip to content

Instantly share code, notes, and snippets.

@fabiodbr
Forked from alpgarcia/github-token-for-git.md
Last active February 7, 2021 16:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fabiodbr/3131fec2685a7e6411f61753a70da34c to your computer and use it in GitHub Desktop.
Save fabiodbr/3131fec2685a7e6411f61753a70da34c to your computer and use it in GitHub Desktop.
Configure GitHub token with gnome-keyring
  1. git --version
git version 2.17.1
  1. sudo apt-get install libsecret-1-0 libsecret-1-dev
  2. cd /usr/share/doc/git/contrib/credential/libsecret
  3. sudo make
  4. git config --global credential.helper /usr/share/doc/git/contrib/credential/libsecret/git-credential-libsecret
  5. Next time Git asked for GitHub's username an password, just write your username and paste your token and they'll be stored in your keyring.

Ansible snippet:

- name: Use gnome keyring credential helper (gui password prompt)
  when: '"gnome-keyring-credential-helper" is defined and "gnome-keyring-credential-helper" in configure'
  block:
    - name: "[gnome-keyring-credential-helper]: packages"
      apt:
        name: "{{ item }}"
        state: latest
      loop:
        - libsecret-1-0
        - libsecret-1-dev
    - name: "[gnome-keyring-credential-helper]: verify if already compiled"
      stat:
        path: /usr/share/doc/git/contrib/credential/libsecret/git-credential-libsecret
      register: git_credential
    - name: "[gnome-keyring-credential-helper]: build library"
      when: not git_credential.stat.exists
      make:
        chdir: /usr/share/doc/git/contrib/credential/libsecret
        target: all
    - name: "[gnome-keyring-credential-helper]: configure git global credential.helper"
      git_config:
        name: credential.helper
        scope: global
        value: "/usr/share/doc/git/contrib/credential/libsecret/git-credential-libsecret"
      changed_when: False
@Yiming-M
Copy link

Yiming-M commented Feb 7, 2021

What you have wrote is very helpful. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment