我正在尝试使用我的终端将代码推送到我的私有github存储库中,但无法正常工作。
我尝试使用git push命令尝试将文件添加到存储库中。
git remote add origin <url for the github repo>
然后我使用以下代码将其推送到存储库中
git push -u origin master
To https://github.com/arunkumarindosyd1994/git-test.git
! [rejected] master -> master (fetch first)
error: failed to push some refs to 'https://github.com/arunkumarindosyd1994/git-test.git'
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first integrate the remote changes
hint: (e.g., 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
在这种情况下如何获得帮助?
答案 0 :(得分:2)
git push
以从服务器获取最新更改。git init
git remote add origin git@github.com:somecompany/some-repo.git
git add .
git pull origin master
备份您的更改。答案 1 :(得分:1)
如果您仔细查看错误消息,它会为您提供以下提示:
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提取并合并。 因此,如果要执行git fetch,则必须显式合并更改。但是强烈建议使用git fetch,因为它比git pull更安全。
此后,您必须解决合并冲突(如果有)并提交更改。
现在您可以将更改推送到git。