首先在碼雲上面新建一個項目。
在新建項目時 選擇不添加README.md文件(重要)
然后,進行如下操作:
1.cd 切換到工程目錄
2.Git全局設置
git config --globaluser.name "user.name"
git config --global user.email "user.email" //如果已經設定過則可以跳過這步
3.git init //初始化一個git 倉庫
4. touch README.md //創建幫助文件
5. git add -A //添加所有文件
6. git commit -a -m "注釋內容” //添加注釋
7. git remote add origin https://git.oschina.net/username/xxx.git(你的遠程倉庫地址,即是碼雲的項目路徑) //和遠程倉庫進行關聯
如果報錯:fatal: remote origin already exists.
解決方法:
1、先輸入$ git remote rm origin
2、再輸入$ git remote add origin git@github.com:djqiang/gitdemo.git 就不會報錯了!
3、如果輸入$ git remote rm origin 還是報錯的話,error: Could not remove config section 'remote.origin'. 我們需要修改gitconfig文件的內容
4、找到你的github的安裝路徑,我的是C:\Users\ASUS\AppData\Local\GitHub\PortableGit_ca477551eeb4aea0e4ae9fcd3358bd96720bb5c8\etc
5、找到一個名為gitconfig的文件,打開它把里面的[remote "origin"]那一行刪掉就好了!
8. git push origin master //上傳倉庫到碼雲
如果報錯: failed to push some refs to 'git@github.com:
可能原因:
GitHub遠程倉庫中的README.md文件不在本地倉庫中。
解決方案:
git pull --rebase origin master #拉取合並代碼 git push -u origin master #上傳倉庫到碼雲
- warning: LF will be replaced by CRLF in ......
- The file will have its original line endings in your working directory.
解決方法:
git config --global core.autocrlf false
就可以解決了。
原因是路徑中存在 / 的符號轉義問題,false就是不轉換符號。
而默認是true,相當於把路徑的 / 符號進行轉義,這樣添加的時候就有問題
