Remove credentials from Git

后端 未结 30 1666
不知归路
不知归路 2020-11-21 10:13

I\'m working with several repositories, but lately I was just working in our internal one and all was great.

Today I had to commit and push code into other one, but

30条回答
  •  伪装坚强ぢ
    2020-11-21 10:43

    To add to @ericbn 's https://stackoverflow.com/a/41111629/579827 here are sample commands I've embedded in a script I run to update all my passwords whenever they are renewed. It's probably not usable as-is as it's quite specific but it shows real life usage of cmdkey.exe.

    ⚠ This is a shell script run in cygwin

    ⚠ This works because I use private git repos that all authenticate with the same password (you probably don't want to loop over with the same credentials, but you may reuse this sample /list command to extract a list of already registered credentials) ⚠

    entries=`cmdkey.exe /list: | grep git | sed -r -e 's/^[^:]+:\s*(.*)$/\1/gm'`
    for entry in ${entries}
    do
        cmdkey.exe "/delete:${entry}"
        cmdkey.exe "/generic:${entry}" "/user:${GIT_USERNAME}" "/pass:${GIT_PASSWORD}"
    done
    

提交回复
热议问题