我试图将我的文件代码推入GitHub,但它不起作用

我试图将我的文件代码推入GitHub,但它不起作用,git,github,Git,Github,我试图使用我的终端将我的代码推入我的私有github存储库,但它不起作用 我尝试使用gitpush命令将文件添加到存储库中 git remote add origin <url for the github repo> 在这种情况下,我如何获得帮助 执行git pull,从服务器获取最新的更改 解决任何合并冲突 提交任何合并冲突更改 git push将更改备份 如果您仔细查看错误消息,它会给您以下提示: not have locally. This is usually caus

我试图使用我的终端将我的代码推入我的私有github存储库,但它不起作用

我尝试使用gitpush命令将文件添加到存储库中

git remote add origin <url for the github repo>

在这种情况下,我如何获得帮助

  • 执行
    git pull
    ,从服务器获取最新的更改
  • 解决任何合并冲突
  • 提交任何合并冲突更改
  • git push
    将更改备份

  • 如果您仔细查看错误消息,它会给您以下提示:

    not have locally. This is usually caused by another repository pushing
    to the same ref. You may want to first integrate the remote changes
    (e.g., 'git pull ...') before pushing again." 
    
    这意味着您的本地存储库已经过时,并且在远程存储库中有一些本地存储库中不存在的新更改

    您首先需要通过以下方式使本地存储库更新:
    git fetch
    git pull

    git pull=git fetch和merge。 因此,如果您正在执行git fetch,则必须显式合并更改。但强烈建议使用git fetch,因为它比git pull更安全

    之后,您必须解决合并冲突(如果有)并提交更改

    现在您可以将更改推送到git

    not have locally. This is usually caused by another repository pushing
    to the same ref. You may want to first integrate the remote changes
    (e.g., 'git pull ...') before pushing again."