我刚刚去github并创建了一个新项目,到目前为止它只有一个自述文件和gitignore文件。但我在当地的一个项目,我添加使用如何在git中推新项目,同时忽略远程中的新文件(如自述文件)
git init
git add .
git commit -m "initial commit"
git remote add origin https://github.com/user/repo.git
我想用git push -u origin master
推我的项目的Git,但我得到含有这种
$ git push -u origin master
To https://github.com/user/project.com
! [rejected] master -> master (fetch first)
error: failed to push some refs to 'https://github.com/user/project.com'
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.
我明白这个错误背后的逻辑错误信息,但解决方案是什么? 我不想拉,因为它可能会抹掉我的本地.gitignore文件,无论如何无视这种情况下不用强制推送?
可以的Git拉--rebase,它会告诉你,如果有冲突。 –
推--force标志时应该这样做 – Matt
@martinjakubik不会--rebase删除一些文件喜欢? – user7342807