【问题标题】:Unable to update my GitHub from my Mac无法从我的 Mac 更新我的 GitHub
【发布时间】:2015-03-05 15:38:41
【问题描述】:

为什么我无法从我的 Mac 更新我的 GitHub?

git status 产生以下内容:

On branch master Changes to be committed:   (use "git reset HEAD
<file>..." to unstage)

    new file:   file.test

Untracked files:   (use "git add <file>..." to include in what will be
committed)

    .DS_Store

git push 产生以下内容;

fatal: The current branch master has no upstream branch. To push the
current branch and set the remote as upstream, use

    git push --set-upstream origin master

【问题讨论】:

    标签: macos git github terminal


    【解决方案1】:

    你需要git add .,然后是git commit -m "My commit message",然后是git push -u origin master

    这会将上游设置为origin/master。继续前进,只需git push 就足够了

    【讨论】:

    • git push -u origin master 到github.com/username/FXTrader.git! [rejected] master -> master (non-fast-forward) error: failed to push some refs to 'github.com/username/FXTrader.git' 提示:更新被拒绝,因为你当前分支的尖端在提示后面:它的远程对应。在再次推送之前集成远程更改(例如提示:'git pull ...')。提示:有关详细信息,请参阅“git push --help”中的“关于快进的说明”。
    • 先做一个git pull -u origin master
    【解决方案2】:

    Git 通过提交工作 - 基本上是您的存储库在给定时间点的样子的快照。您需要先将文件提交到您的存储库,然后才能将它们实际推送到 GitHub。

    所以您的第一步是将文件添加到“暂存区”

    git add file.text # you can do git add . but this will add all files which you may not always want
    

    现在您可以使用

    查看“暂存区”的当前状态
    git status
    

    这将确保您只提交您想要添加的更改。

    现在您可以提交更改。提交只会“保存”暂存区中的文件。

    git commit -m "A useful description of what you did since your last commit"
    

    好的,现在您可以推送了。假设你是从 GitHub 克隆的,你可以运行

    git push origin master
    

    但是如果你使用git init 创建了这个存储库,你需要告诉 git 你在某个地方有一个远程存储库。通过运行来做到这一点

    git remote add https://github.com/<usernane>/<repo_name> origin
    

    此来源是您希望与远程存储库关联的名称。 “Origin”是最常见的,但您可能有其他遥控器,如“backup”或“code_review”,用于不同的用例。

    添加远程仓库后,您实际上可以使用

    推送到它
    git push origin master
    

    同样,origin 是您的远程仓库的名称,“master”是一个“分支”名称。

    您可以添加 -u 标志,以便 git 假定您要推送到源。所以以后你只需要运行

    git push 
    

    【讨论】:

      【解决方案3】:

      收听错误消息。 :)

      您目前有一个未跟踪的文件,.DS_Store,我碰巧知道这是一个系统文件,因此您可能希望将其添加到您的 .gitignore

      至于尝试推送上游,你需要为每个分支设置你的上游,所以你只需要输入命令

      $ git push --set-upstream origin master
      

      然后做一个简单的

      $ git push
      

      将您的更改发送到 github。

      如果您要推送到在线的分支在您之前,那么您可能需要先发送git pull 以获取更改,然后再发送git push

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2010-10-21
        • 2018-01-12
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-04-27
        相关资源
        最近更新 更多