附载码云的使用教程地址:http://www.jianshu.com/p/084e0aabbab3
问题一:执行Git remote add origin https://github.com/XXXXXXX/gif.git
fatal: remote origin already exists.
出现此问题时,git remote显示所有的远程库,使用命令git remote rm origin删除该origin。
问题二: git push -u origin master推送本地库到github
fatal: I don't handle protocol 'git@https'
出现此问题时,使用命令git remote add origin http://github.com/XXXXXXX/gif.git 。
问题三:执行$ git push -u origin master
Username for 'https://github.com/XXXXXXX/gif.git'
! [rejected] master -> master (fetch first)
error: failed to push some refs to 'https://github.com/XXXXXXX/gif.git'
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.
错误的主要原因是git仓库上已经存在readme文件,故在提交时可能会存在冲突,这时您需要选择的是保留线上的文件或者舍弃线上的文件,如果您舍弃线上的 文 件,则在推送时选择强制推送,强制推送需要执行下面的命令
git push origin master -f
如果您选择保留线上的readme文件,则需要先执行
git pull origin master
Git使用步骤:
在GitHub上新建一个abc仓库。
在本地新建Git仓库:
1、mkdir abc
2、cd abc
3、git init
4、将文件添加进去(file)
5、git add file1 file2 file...
6、git commit -m "add files"
7、git remote add origin https://git.oschina.net/xxx/abc.git
8、git push -u origin master
在这里,出现了错误提示:
error: failed to push some refs to 'https://git.oschina.net/xxx/abc.git'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Merge the remote changes (e.g. 'git pull')
hint: before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
这里提示推送失败,因为在GitHub上初始化了一个README.MD文件,远程仓库中的文件比本地的要新,所以要使用git pull要把最新的文件抓下来,与本地的文件合并之后在提交。
9、git pull
提示错误:
remote: Counting objects: 5, done.
remote: Compressing objects: 100% (2/2), done.
remote: Total 3 (delta 0), reused 3 (delta 0)
Unpacking objects: 100% (3/3), done.
From github.com:michaelliao/learngit
fc38031..291bea8 dev -> origin/master
There is no tracking information for the current branch.
Please specify which branch you want to merge with.
See git-pull(1) for details
git pull <remote> <branch>
原因是没有指定本地master和远程origin/master的连接。
10、设置连接
$ git branch --set-upstream master origin/master
11、git pull
12、然后提交
git commit -m "merge README.MD"
13、git push -u origin master
完成本地上传远程仓库