【问题标题】:Add existing Android Studio project to existing GitHub repository将现有的 Android Studio 项目添加到现有的 GitHub 存储库
【发布时间】:2018-11-22 12:54:25
【问题描述】:

我在 Android Studio 中创建了一个新项目,我想将它添加到当前为空的现有 GitHub 存储库中。

我已经尝试过这个问题的答案:Replace GitHub repository with a new Android Studio project while preserving old commits 但是一旦我到达最后的git push,我就会收到一条错误消息fatal: No configured push destination.

我也尝试过https://github.community/t5/How-to-use-Git-and-GitHub/How-to-link-an-existing-Android-Studio-Project-to-an-existing/td-p/1946,但这会将项目上传到错误的 GitHub 帐户。我有两个 GitHub 帐户,我认为这是这个解决方案的问题,我已经退出了我不需要的帐户。

还有其他方法可以连接到现有的 GitHub 存储库吗?

【问题讨论】:

    标签: git android-studio github


    【解决方案1】:

    您要做的第一件事是创建本地存储库(在您的机器上)

    git init
    

    当您尝试执行git push 时,我假设您已经这样做了。 所以接下来你要做的就是为你的本地仓库定义一个远程仓库(github)来推送:

    git remote add origin https://github.com/<user>/<repo>.git
    

    然后您可以使用push,但需要更多参数。

    git push -u origin master
    

    这将告诉 git 将您的提交推送到您的 origin 远程存储库上的 master 分支

    更多关于git remote的信息在这里:https://help.github.com/articles/adding-a-remote/

    【讨论】:

      【解决方案2】:

      很可能您忘记添加遥控器。您可以使用以下命令检查您的远程列表。

       git remote -v
      

      如果不存在来源,请尝试使用以下命令添加遥控器:

      git remote add <remote name> <remote url>
      

      (远程 url 是你的仓库 url,例如:https://github.com/user/repo.git

      然后你可以使用以下命令推送:

      git push <remote name> <your branch name>
      

      【讨论】:

        猜你喜欢
        • 2013-01-04
        • 2014-12-08
        • 1970-01-01
        • 2011-11-04
        • 1970-01-01
        • 1970-01-01
        • 2016-05-14
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多