我有一个非常奇怪的问题与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

什么好主意吗?


当前回答

首先在命令行上创建一个新的存储库,命名为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

其他回答

我需要杀死凭证帮助进程(有多个),它在再次提供凭证后解决了这个问题。

killall git-credential-cache——守护进程

我的代码片段:

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"

自2021年5月以来,我(和许多其他人)就遇到了这个问题。 有些东西似乎已经改变了行动/checkout@v2 (GitHub问题:https://github.com/actions/checkout/issues/254)

我通过使用此步骤更改运行程序对回购进行身份验证的方式来解决这个问题。

- name: Bump version
    env:
      NODE_AUTH_TOKEN: ${{secrets.GITHUB_TOKEN}}
    run: |
      npm run release
      git remote rm origin
      git remote add origin https://${{github.actor}}:${{secrets.GITHUB_TOKEN}}@github.com/project/repo.git
      git remote -v # for debug only 
      git show-ref # for debug only 
      git push --follow-tags origin HEAD:master

所有你需要做的是改变回购url。用户名和密码将在运行时由GitHub运行器替换。这适用于actions/checkout@v1和actions/checkout@v2(还没有测试其他)。

此外,你在网上找到的许多代码片段已经带有权限限制,这将阻止你推回回购

permissions:
   packages: write
   contents: read

确保你删除了这个或授予你的动作内容:如果你需要推送一个标签或提交发行说明和包碰撞,写许可。

git remote rm origin
git remote add origin <remote url>

如果你的repo之前工作正常,突然弹出这个错误,最有可能的原因是你的git被认证为其他用户,没有访问存储库的权限。因此,为了进行推送,您所需要做的就是在git命令中指定正确的用户名和密码。所以,一个github回购的推命令看起来像:

git push https://youruser:password@github.com/user/reponame.git

用户名和密码需要进行url转义,因此@应该被%40取代,等等。