推送到裸 git 存储库而不事先克隆它

Push to bare git repository without cloning it beforehand

我目前正在尝试将一些文件保存在裸 git 存储库中,如下所述:

https://news.ycombinator.com/item?id=11071754

但是,我在 Git 上尝试 Windows,而不是在 Linux 机器上。裸 git 存储库已创建,但我正在努力使 push 正常工作。这就是我所做的:

username@hostname MINGW64 ~/Desktop
$ mkdir .myconf

username@hostname MINGW64 ~/Desktop
$ git init --bare "/c/Users/username/Desktop/.myconf"
Initialized empty Git repository in C:/Users/username/Desktop/.myconf/

username@hostname MINGW64 ~/Desktop
$ alias config="git --git-dir='/c/Users/username/Desktop/.myconf' --work-tree='/c/Users/username/Desktop/'"

username@hostname MINGW64 ~/Desktop
$ config config status.showUntrackedFiles no

username@hostname MINGW64 ~/Desktop
$ config status
On branch master

Initial commit

nothing to commit (create/copy files and use "git add" to track)

username@hostname MINGW64 ~/Desktop
$ config add test.txt

username@hostname MINGW64 ~/Desktop
$ config commit -m "Added test file."
[master (root-commit) a587ec1] Added test file.
 1 file changed, 1 insertion(+)
 create mode 100644 test.txt

到目前为止一切正常。但是,当我尝试 push 时,会发生这种情况:

username@hostname MINGW64 ~/Desktop
$ config push
fatal: No configured push destination.
Either specify the URL from the command-line or configure a remote repository using

    git remote add <name> <url>

and then push using the remote name

    git push <name>

还有一个 pushorigin master 不工作:

username@hostname MINGW64 ~/Desktop
$ config push origin master
fatal: 'origin' 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.

显然,git 想要一个推送目的地。

我没有看到设置这样的目的地是链接描述中的必要步骤(在任何派生的博客文章中也没有),我不确定如何使用 Git for Windows.如何解决?

您需要定义一个 remote 以便 Git 知道要推送到哪里。默认的 remote 称为 origin 并将成为 Git 推送到的 url。

例如,如果您尝试推送到 Linux 内核,则命令为:

git remote add origin https://github.com/torvalds/linux.git

您需要告诉 git 远程存储库在哪里。使用:

config remote add origin "<path>"

路径是 url 或目录。

如果您想了解为什么 .myconfig 不是您推送的远程仓库,请阅读以下内容:http://www.sbf5.com/~cduan/technical/git/

对于git这样的分布式VCS来说,push是一种本地分支和远程分支之间的同步机制。在推送之前必须指定本地分支和远程分支的连接,对于git,它引用为"upstream"或"tracking"。

如果你想在没有克隆的情况下将你的提交推送到远程。您可以将远程存储库添加为新的远程存储库,签出您要提交的分支并使其跟踪远程分支,将您的修改添加到这个新分支并进行推送。