我有一个非常奇怪的问题与git和github。当我试着推的时候,我得到:

git push -u origin master
ERROR: Repository not found.
fatal: The remote end hung up unexpectedly

我添加了遥控器:

git remote add origin git@github.com:account-name/repo-name.git

什么好主意吗?


当前回答

我的代码片段:

environment {
    ...
    ...
    git_repo = 'my-repo'
}

stage ('Update Helm Chart') {
    steps {
        echo 'Updating values.xml file with latest Docker image tag'

        withCredentials([usernamePassword(credentialsId: '6bgg7dd45-c65f13-4275-a96ddehdv67gdr', usernameVariable: 'GIT_USER', passwordVariable: 'GIT_PASS')]) {
            sh '''
                git checkout ${git_branch}
                ...
                ...
                git remote set-url origin "http://${GIT_USER}:${GIT_PASS}@git.example.com/scm/${git_repo}.git"
                git push origin ${git_branch}
            '''
        }
    }
}

我的Git用户名是deploy.user@example.com,所以我必须首先URL编码@ %40。在URL编码之后,我的用户名变成了deploy.user%40example.com。

然而,我仍然得到以下错误:

fatal: repository 'http://****:****@git.example.com/scm/my-repo.git/' not found

经过一些试验和错误,我发现,如果我不使用变量的用户名,而是硬编码它,它的工作。

git remote set-url origin "http://deploy.user%40example.com:${GIT_PASS}@git.example.com/scm/${git_repo}.git"

其他回答

有类似的问题。问题的根源是我遵循了一些关于向Github添加新存储库的在线教程。

只要去Github,创建一个新的repo,它会要求你添加一个README,不要添加它。创建它,你会得到如何推送的指导。

它类似于接下来的两行:

git remote add origin https://github.com/YOUR_USER/your-repo.git
git push -u origin master

这个答案是IntelliJ产品(如IDEA / WebStorm / PHPStorm)在使用组织时所特有的。

我有这个问题与WebStorm时,试图推动到一个存储库的一部分 一个组织,同时推送到我正常范围内的存储库 私人账户有效。 此外,用IntelliJ IDEA推送到我的组织存储库也起作用了

所以我认为这可能只是与两个ide之间的设置不同有关,我发现我在WebStorm中启用了“使用凭据助手”复选框,而在IDEA中禁用了。

禁用凭据助手使其工作!!

首先在命令行上创建一个新的存储库,命名为adim .git

在命令行上创建一个新的存储库

触摸README.md git init git添加README.md Git commit -m "第一次提交" git远程添加origin https://github.com/your_name/Ademo.git Git push -u origin master

从命令行推送现有存储库

git远程添加origin https://github.com/your_name/Ademo.git Git push -u origin master

一个问题,这可能是显而易见的一些,我没有看到这里提到,可能是你有ssh密钥访问,但你正试图通过https连接你的本地回购到远程。

如果是这种情况,那么下面的命令应该可以解决这个问题:

$ git remote -v
origin  https://github.com/private-repo.git (fetch)
origin  https://github.com/private-repo.git (push)
$ git remote rm origin
$ git remote add origin git@github.com:private-repo.git
$ git remote -v
origin  git@github.com:private-repo.git (fetch)
origin  git@github.com:private-repo.git (push)

请注意,上述工作的前提是: 您当前的远程名为origin,并且您已经拥有 生成SSH密钥连接到您的github帐户 你已经有一个SSH密钥与你的github帐户相关联(并在本地连接) 你有正确的权限(读/写)设置在github为这个回购的设置。

如果你属于一个组在Github检查你有写访问权。