1 先下載git for windows
然后一直點下一步安裝.
2 安裝之后,選擇git gui.生成ssh 鏈接 git 公鑰.
用命令也可以:
$ ssh-keygen -t rsa -C "your_emali@youemal.com"
然后輸入密碼.
建議用第一種方式。第二種網上說是可以,但是我沒成功過。
然后輸入密碼。
3 將公鑰添加到開源中國上,或者是github中
在開源中國中新建一個公鑰,然后將.ssh文件夾下的id_ras_pub中的內容復制到文本框中,這里的title可以隨意.
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