Ant*_*dev 127 git bash command
我想在一行中执行此命令:
git pull && [my passphrase]
Run Code Online (Sandbox Code Playgroud)
怎么做?
eis*_*eis 142
这不是你要求的,但对于http(s):
https://user:pass@domain/repo但不是真的推荐,因为它会在很多地方显示你的用户/通行证......凭证助手的使用示例
git config credential.helper store - 无限期地存储凭证.git config credential.helper 'cache --timeout=3600'- 商店60分钟对于基于ssh的访问,您将使用ssh代理,该代理将在需要时提供ssh密钥.这将需要在您的计算机上生成密钥,将公钥存储在远程服务器上并将私钥添加到相关的密钥库.
hol*_*ero 106
我找到了一种在命令行上为https连接提供凭据的方法.您只需要指定git pull的完整URL并在其中包含凭据:
git pull https://username:password@mygithost.com/my/repository
Run Code Online (Sandbox Code Playgroud)
您之前不需要使用凭据克隆存储库,这意味着您的凭据不会最终进入.git/config.(但请确保您的shell不会背叛您并将命令行存储在历史文件中.)
Jiv*_*van 34
不直接回答这个问题,但是我在寻找一种方法时发现了这个问题,基本上,每次我拉远程服务器时都不会重新输入密码.
好吧,git允许您在有限的时间内缓存凭据.它是可定制的git config,本页解释得非常好:
https://help.github.com/articles/caching-your-github-password-in-git/#platform-linux
在终端中,运行:
$ git config --global credential.helper cache
# Set git to use the credential memory cache
Run Code Online (Sandbox Code Playgroud)
要自定义缓存超时,您可以执行以下操作:
$ git config --global credential.helper 'cache --timeout=3600'
# Set the cache to timeout after 1 hour (setting is in seconds)
Run Code Online (Sandbox Code Playgroud)
然后,您的凭据将存储在内存中所需的时间.
小智 11
如果密码中没有@,则下面的 cmd 将起作用:git pull https://username:pass@word@mygithost.com/my/repository
如果密码中
有 @,则将其替换为 %40,如下所示:
git pull https://username:pass%40word@mygithost.com/my/repository
Bix*_*Bix 11
我刚刚经历过这个,所以提供了我的答案,因为我最终使用了Gitlab 访问令牌,尽管有些可能需要Github 访问令牌
我更喜欢使用 SSH,但 gitlab 有一个错误阻止了这一点。将我的密码放在 .netrc 或 URL 中并不理想。凭据管理器需要在服务器重新启动时重新启动,这并不理想。
因此我选择了一个访问令牌,可以像这样使用:git clone https://<username>:<accessToken>@gitlab.com/ownerName/projectName.git
访问令牌与 url 一起存储,因此这并不安全,但它比使用 username:password 更安全,因为访问令牌可以限制为某些操作并且可以轻松撤销。
一旦克隆下来(或者手动更新 URL),您的所有 git 请求都将使用访问令牌,因为它存储在 URL 中。
如果您希望更新已经克隆的存储库,这些命令可能会有所帮助:
git remote show origin
git remote remove origin
git remote add origin https://<username>:<accessToken>@gitlab.com/ownerName/projectName.git
Run Code Online (Sandbox Code Playgroud)
编辑:请务必检查下面的评论。我添加了 2 个重要注释。
小智 9
使用凭据帮助程序命令行选项:
git -c credential.helper='!f() { echo "password=mysecretpassword"; }; f' fetch origin
Run Code Online (Sandbox Code Playgroud)
小智 6
在 Google 和 stackoverflow 搜索了一段时间后,我没有找到我的问题的答案,所以我想在这里分享我的解决方案。
git config --global credential.helper "/bin/bash /git_creds.sh"
echo '#!/bin/bash' > /git_creds.sh
echo "sleep 1" >> /git_creds.sh
echo "echo username=$SERVICE_USER" >> /git_creds.sh
echo "echo password=$SERVICE_PASS" >> /git_creds.sh
# to test it
git clone https://my-scm-provider.com/project.git
Run Code Online (Sandbox Code Playgroud)
我也为 Windows 做过。完整答案在这里
请注意,git 凭证助手“存储”将存储未加密密码的方式随 Git 2.5+(2014 年第二季度)发生变化。
见提交17c7f4d通过JUNIOÇ滨野(gitster)
credential-xdg调整
store凭据助手的示例“ ”后端以在指定时遵守 XDG 配置文件位置。
医生现在说:
如果未指定:
- 将从
~/.git-credentials和 中搜索凭据$XDG_CONFIG_HOME/git/credentials,并且~/.git-credentials如果存在,或者$XDG_CONFIG_HOME/git/credentials如果存在而前者不存在,则将写入凭据。
您可以只使用用户名而不需要使用密码,因为在 git bash 中会提示密码。
git pull https://username@github.com/username/myrepo
Run Code Online (Sandbox Code Playgroud)
如果您希望在 Gitlab 上的 CI/CD 脚本中执行此操作 ( gitlab-ci.yml)。你可以使用
git pull $CI_REPOSITORY_URL
Run Code Online (Sandbox Code Playgroud)
这将翻译成这样:
git pull https://gitlab-ci-token:[MASKED]@gitlab.com/gitlab-examples/ci-debug-trace.gi
Run Code Online (Sandbox Code Playgroud)
而且我很确定它使用的令牌是临时/每个作业令牌 - 因此这种方法的安全漏洞大大减少了。
| 归档时间: |
|
| 查看次数: |
225805 次 |
| 最近记录: |