Git在推送时创建远程存储库 [英] Git create remote repository on push

查看:182
本文介绍了Git在推送时创建远程存储库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在试图找出这一点,但我很难做到这一点。我目前正在开发一个开源项目,该项目要求我允许用户 推送到远程存储库,而不存在存在。我想避免手动登录到服务器并运行 git init git init --bare



出于显而易见的原因,当我尝试将本地存储库推送到不指向远程服务器上现有存储库的路径时,出现以下错误:

 致命:'/ var / repositories / myrepo'似乎不是git存储库
致命:远程端意外挂起

但是我希望能够运行例如以下命令:

  git push origin master 

如果它还不存在,请在 / var / repositories 中创建 / myrepo 。我将如何能够做到这一点?我假设它是某种可能在远程服务器上设置的(全局)git config 设置,或者是本地设置的(存储库特定)git config ,但我无法找到答案。



任何帮助都将非常感谢!



谢谢! / strong>

解决方案


  1. 结帐并跟踪远程分支:

      git checkout -t origin \funbranch 


  2. 关闭它:

      git checkout -b mybranch 


  3. 向上推新的,它会自动在远程创建一个新分支:

      git push origin mybranch 


  4. ol>

    它应该说创建新的远程分支原点\mybranch

    如果您仍然收到远程挂断起来,这听起来像一个安全的事情。您是否正确安装了SSH密钥,并且您是否拥有远程服务器上的写权限?



    大多数开源项目的工作方式,您必须创建一个fork(a克隆固有地),你用来做你的工作,因为大多数时候你没有写入权限回购。当你有改变时,你将发送一个拉取请求给存储库所有者,他/她将从你的分支中提取他们想要的改变。


    I have been trying to figure this one out but I am having a hard time doing so. I am currently working on an open source project that requires me to allow a user to push to remote repository without it already existing there. I want to avoid manually logging in to a server and running git init or git init --bare.

    For obvious reasons, I get the following error when trying to push my local repository to a path that doesn't point to an existing repository on the remote server:

    fatal: '/var/repositories/myrepo' does not appear to be a git repository
    fatal: The remote end hung up unexpectedly
    

    But I would like to be able to run for example the following command:

    git push origin master
    

    And have that create /myrepo in /var/repositories if it does not yet exist. How would I be able to accomplish this? I would assume it is some kind of (global) git config setting you would probably set on the remote server, or otherwise a (repository specific) git config locally, but I couldn't figure it out.

    Any help would be much appreciated!

    Thanks!

    解决方案

    1. Checkout and track the branch from the remote:

      git checkout -t origin\funbranch
      

    2. Branch off of it:

      git checkout -b mybranch
      

    3. Push your new one up, it will create a new branch automatically on the remote:

      git push origin mybranch
      

    It should say "created new remote branch origin\mybranch"

    If you are still getting "Remote end Hung up", it sounds like a security thing. Do you have SSH keys installed correctly, and do you have write permissions on the remote server?

    The way most open source projects work, you have to create a fork (a clone inherently) that you use to do your work because most of the time you don't have write permissions to the repo. When you have changes, you will then send a pull request to the repository owner, and he/she will pull from your fork the changes that they want.

    这篇关于Git在推送时创建远程存储库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆