推送到远程仓库时git push错误

标签 git github version-control

我们是 Git 的新手,计划在 Windows 中创建本地存储库并通过局域网在团队之间共享。我们已按照以下步骤操作并在将存储库推送到其他存储库时遇到问题。

创建新文件夹 D:/Git/Repository 并使用 Windows 文件共享选项将 Git 文件夹共享给团队成员。

$ cd d:/Git/Repository

$ git init

Initialized empty Git repository in d:/git/Repository/.git/

user@host /d/git/Repository (master)

将新文件 (Readme.txt) 添加到存储库位置

$ git add Readme.txt

user@host /d/git/Repository (master)

$ git commit -a -m 'Added Readme'

[master (root-commit) f072a76] Added Readme
 1 file changed, 14 insertions(+)
create mode 100644 Readme.txt
user@host /d/git/Repository (master)

再次使用 –bare 选项初始化存储库 $ git --bare init

Initialized empty Git repository in d:/git/Repository/

user@host /d/git/Repository (master)

添加到远程

$ git remote add origin file:////host/D/Git/Repository

user@host /d/git/Repository (master)

尝试将更改推送到其他存储库,出现一些 fatal error

$ git push origin master

fatal: '//host/D/Git/Repository' does not appear to be a git repository

fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

user@host /d/git/Repository (master)

最佳答案

你应该避免使用工作目录重新初始化一个 repo(git 内部文件将与你的项目文件混淆)并且你应该避免在“远程”repo 中有一个工作树。

在这种情况下,git 无法在您的文件系统上找到 //host/D/Git/Repository

假设你已经在 Github 上准备了一个项目:

$ git clone <url to project on Github> c:/Git/Repository
$ git add Readme.txt
$ git commit -a -m 'Added Readme'
$ git fetch origin
$ git push origin master

您不应与其他开发人员共享此私有(private)本地存储库。

如果您需要文件系统上的共享存储库(假设“d:”是共享磁盘):

$ cd d:/git/sharedrepo
$ git init --bare --shared

然后每个开发人员将共享仓库克隆到私有(private)本地仓库中:

$ git clone d:/git/sharedrepo c:/git/myrepo

关于推送到远程仓库时git push错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32179216/

相关文章:

github - 内部可见 jenkins 实例中 jenkins 的 webhook 代理

linux - 自动应答 bash 脚本提示

git - 如何防止 Gitlab 在分支 merge 时创建额外的 merge 提交

linux - 无法在本地网络服务器上注册 git runner

git - 从 GitHub 上的 Pull Request 删除文件

Git rebase 噪声

sql-server - SqlServer 存储过程和 View 的版本控制/代码存储库

android - 如何 merge 分支并忽略flutter生成的二进制文件中的冲突?

git - 使用 Git 插件时 Visual Studio 中的 diff 工具

git - 如何将 TAG 添加到 Git 和 Bitbucket 中已经提交的