How to use gpg-agent for git bulk character

My question is about the gpg-agent command that caches gpg keys and passwords.

I want to know how to use it so that I can run several git commands with the -s tag in a script without having to enter my missing gpg phrase every time.

The initial version of my script looks something like this:

git branch -r | grep origin | grep pattern | when reading BRANCH; do TAG = basename $BRANCH ; git tag -s -m "tag $ TAG release" "$ TAG" "$ BRANCH"; done;

I have two use cases:

  • I have about 20 release branches that I want to convert to tags.
  • I have about 40 release tags that I want to repeat in order to follow the new naming convention.

I am looking for the command line for gpg-agent to run, and then the gpg command that I need to run in order to get my missing phrase that will be used when I do git tag -s

+4
source share
1 answer

This can be done by running gpg-agent before running the script. For instance:

 $ eval $( gpg-agent --daemon ) $ for branch in $( git branch -r | grep PATTERN ); do > tag="$( basename $BRANCH )" > git tag -sm "tag $tag release" "$tag" "$branch" > done 

You will be prompted to enter a password for the first character (unless gpg-agent has already been used before the first character). If you use the above method, be sure to start the agent after completion (for example, pkill gpg-agent ).

More information about starting the agent can be found here: http://www.gnupg.org/documentation/manuals/gnupg/Invoking-GPG_002dAGENT.html

+2
source

Source: https://habr.com/ru/post/1401517/


All Articles