git提交遠程報錯[rejected] master -> master (fetch first)

1 先下載git for windowshtml

而後一直點下一步安裝.git

2 安裝以後,選擇git gui.生成ssh 連接 git 公鑰.github

用命令也能夠:web

$ ssh-keygen -t rsa -C "your_emali@youemal.com"windows

而後輸入密碼.ssh

建議用第一種方式。第二種網上說是能夠,可是我沒成功過。測試

而後輸入密碼。fetch

3 將公鑰添加到開源中國上,或者是github中ui

在開源中國中新建一個公鑰,而後將.ssh文件夾下的id_ras_pub中的內容複製到文本框中,這裏的title能夠隨意..net

 

4 測試連接:

輸入命令:$ ssh -T git@git.oschina.net

而後輸入yes

若是成功能夠看到你的用戶名和郵箱.

出現錯誤能夠測試:$ ssh -Tv git@git.oschina.net

 

5 設置用戶名和郵箱

$ git  config user.name"you name"

$git  config user.email"you_email@youemal.com"

 

6 而後在web開源中國中建立一個project.

 

7 測試上傳文件

 建立文件夾,須要和你創建的projexct同名。

mkdir hello

cd hello

git init

touch README

git add README

git commit  -m  'frist commit' 

8 提交

git remote add test git@git.oschina.net:web用戶名/hell.git

git push -u test master

如裏有報錯誤:

To git@git.oschina.net:yangzhi/hello.git
 ! [rejected]        master -> master (fetch first)
error: failed to push some refs to 'git@git.oschina.net:yangzhi/hello.git'
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushin
hint: to the same ref. You may want to first merge the remote changes (e.g.
hint: 'git pull') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

 

 

能夠輸入:

git push -f 

能夠ok了.

10 克隆代碼

git clone git@github..com:用戶名/項目名.git

 

來源:http://www.xuebuyuan.com/651322.html

相關文章
相關標籤/搜索