简体   繁体   English

推送到裸git存储库,而无需事先克隆

[英]Push to bare git repository without cloning it beforehand

I am currently trying to save some files in a bare git repository, as described here: 我目前正在尝试将某些文件保存在裸露的git存储库中,如下所述:

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

However, I am trying this with Git for Windows, and not on a Linux machine. 但是,我正在Windows上的Git上尝试此操作,而不是在Linux机器上。 The bare git repository gets created, but I am struggling to get the push working correctly. 裸露的git存储库已创建,但是我正在努力使push正常工作。 This is what I have done: 这是我所做的:

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

Everything so far has worked correctly. 到目前为止,一切工作正常。 However, when I try to push , this happens: 但是,当我尝试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>

Also a push to origin master does not work: 同样, push送到origin 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.

Apparently, git wants a push destination. 显然,git希望推送目的地。

I have not seen that setting such a destination is a necessary step in the linked description (nor in any derived blog posts), and I am unsure how to do that with Git for Windows. 我没有看到在链接描述中(在任何派生的博客文章中)都没有必要设置这样的目的地,而且我不确定如何使用Windows版Git来做到这一点。 How can this be solved? 如何解决呢?

You need to define a remote so Git knows where to push to. 您需要定义一个remote以便Git知道要推送到哪里。 The default remote is called origin and will be the url for Git to push to. 默认的remote称为origin ,它将是Git推送到的URL。

For example, if you were trying to push to the Linux Kernel the command would be: 例如,如果您尝试推送到Linux内核,则命令为:

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

You need to tell git where the remote repository is. 您需要告诉git远程存储库在哪里。 Use: 采用:

config remote add origin "<path>"

Where path is either a url or directory. 其中path是url或目录。

If you wish to understand why .myconfig is not a remote repo that you push to read through something like this: http://www.sbf5.com/~cduan/technical/git/ 如果您想了解为什么.myconfig不是远程回购协议,则可以推送以阅读如下内容: http ://www.sbf5.com/~cduan/technical/git/

For distributed VCS such as git, the push is a synchronization mechanism between local branch and remote branch. 对于git等分布式VCS,推送是本地分支和远程分支之间的同步机制。 you must specify the connection of local branch and remote branch before you do push, for which in git, it reference as "upstream" or "tracking". 您必须先指定本地分支和远程分支的连接,然后再进行推送,在git中,其引用为“上游”或“跟踪”。

If you want to push your commit to remote without clone. 如果您想将提交推送到没有克隆的远程。 you can add the remote repository as a new remote, checkout the branch you want to commit to and make it track the remote branch, add your modification to this new branch and do push. 您可以将远程存储库添加为新的远程服务器,签出要提交的分支并使其跟踪该远程分支,将修改添加到该新分支并进行推送。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM