2017-03-06 50 views
0

我刚刚去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文件,无论如何无视这种情况下不用强制推送?

+1

可以的Git拉--rebase,它会告诉你,如果有冲突。 –

+0

推--force标志时应该这样做 – Matt

+0

@martinjakubik不会--rebase删除一些文件喜欢? – user7342807

回答

0

更新:由于某种原因,此建议从其本地文件系统中删除了用户的文件。

我希望在调查过程中暂时保留它,但我建议您不要按照我的回答。


这应该工作:

git pull (or I prefer git pull --rebase) 

<manually resolve any conflicts by editing the text files> 

git merge --continue (or git rebase --continue if you used rebase above) 

git push 
+0

做过'git pull --rebase'并且它已经被卡住了在'首先,倒带头重播你的作品......' – user7342807

+0

你是在一个代理的背后? –

+0

我正在使用公共WiFi,但回购是私人的.. – user7342807