【问题标题】:Issue with GIT commandGIT 命令的问题
【发布时间】:2017-03-07 19:25:28
【问题描述】:

我正在尝试执行 git clone 命令从 github 存储库克隆源代码。我使用的是 2.11.1 版本。我运行的命令是 git clone https://username:password@github.com/repository.git ./localpath 这在 Windows 机器上运行良好。但是当我从 linux 机器命令执行时,正在删除 @ 并抛出错误。执行失败就像

git clone https://username:passwordgithub.com/repository.git ./localpath Cloning into './localpath'... error: Couldn't resolve host username:passwordgithub.com while accessing

有人可以帮我解决这个问题吗?

【问题讨论】:

  • 您是否尝试过使用 \ 转义 @ 字符?
  • 你用的是什么外壳?
  • @mipadi 正在使用 bash shell。
  • @user2773289 当我使用 jenkins 时,不要使用 \。它失败了。
  • @user2773289,可能与未转义密码冲突。

标签: linux git shell github


【解决方案1】:

将你的 ssh-keygen 生成的 id 注册到 Github,这样它就不会提示你输入密码了。

$ ssh-keygen

无需输入密码。输出你的公钥,然后复制到github

$ cat ~/.ssh/id-rsa.pub

但是,如果你真的想走那条路。 用单引号将它们括起来,或者像下面那样做。

#!/bin/bash
REPO='https://username:password@github.com/repository.git'
LOCAL_PATH='path/to/wherever'

git clone "$REPO" "$LOCAL_PATH"

注意:变量使用双引号

【讨论】:

  • 我们已经在 linux 使用 .netrc 文件,在 windows 使用 _netrc 文件解决了这个问题。
  • @Eldo 很高兴你能够修复它!
猜你喜欢
  • 2019-03-31
  • 2016-04-27
  • 2021-01-21
  • 1970-01-01
  • 2020-11-07
  • 2012-10-20
  • 2010-10-12
  • 2012-09-20
  • 2020-04-13
相关资源
最近更新 更多