Git
- 下载安装git
- 绑定用户
$ git config --global user.name "Your Name"
$ git config --global user.email "email@example.com"
配置ssh
- 查看安装文件目录,是否有.ssh的目录,如果存在查看.ssh目录中是否有id_rsa和id_rsa.pub文件,如果有了,直接到下一步,如果没有,则需要进行免密码登陆的设置:
$ ssh-keygen -t rsa -C "youremail@example.com"
- PS:将id_rsa.pub文件中的内容复制到github网站的setting->SSH and GPG keys->New SSH key中
创建仓库
- 填一下仓库名称,Initialize this repository with a README是可选的,建议在创建时选上,可以在后面省一个步骤。填好之后,点Create repository完成仓库的建立
上传README 文件
- 如果没有在创建仓库时勾选README,用以下代码上传
$ git init
$ touch README.md
$ git add README.md
$ git commit -m 'first_commit'
$ git remote add origin git@github.com:wliii/learngit.git
$ git push origin master
上传文件
- 关联远程仓库
$ git remote add origin git@github.com:wliii/learngit.git
- 将本地内容推送到远程库中
$ git push -u origin master
常见问题
- 关联出现错误 fatal: remote origin already exists,则执行下列语句再进行关联
git remote rm origin
- 推送时出现错误 error:failed to push som refs to…….,则执行下列语句
git pull origin master
-出现以下错误:
$ git push -u origin master
To git@github.com:xxx/xxx.git
! [rejected] master -> master (fetch first)
error: failed to push some refs to ‘git@github.com:xxx/xxx.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.
问题原因:本地仓库中并没有README.md文件
解决方法:
$ git stash
$ git pull --rebase origin master
$ git push -u origin master
大家加油!!