git remote -v //查看库连接地址安装git
获取SSH公钥
$ ssh-keygen -t rsa -C "2855521@qq.com"然后是设置用户密码,嫌麻烦可以一路Enter
title随便输入,Key复制本地~/.ssh目录下的id_rsa.pub文件内的内容。可以用命令获取:
$ cat ~/.ssh/id_rsa.pubgithub添加ssh
在github的setting里的SSH and GPG keys增加ssh。
这个操作一台电脑只要做一次就可以了,之后就不需要重复了。
设置用户信息:
$ git config --global user.name "defnngj"//给自己起个用户名
$ git config --global user.email "defnngj@gmail.com"//填写自己的邮箱
$ makdir ~/hello-world //创建一个项目hello-world
$ cd ~/hello-world //打开这个项目
$ git init //初始化
$ touch README //初始化 README文件在GitHub创建仓库的时候记得选上(没有README文件 会很麻烦)$ git add README //更新README文件
$ git commit -m 'first commit' //提交更新,并注释信息“first commit”
$ git remote add origin git@github.com:defnngj/hello-world.git //连接远程github项目
$ git push -u origin master //将本地项目更新到github项目上去
git tag -a v1 -m '注释' // -a 打版本
创建标签:
创建分支git branch rich 并切换到分支 git checkout rich :
--------------关于可能出现的错误-------------------
【原因】GitHub远程仓库中的README.md文件不在本地仓库中。
【解决方案】
$ git pull --rebase origin master$ git push -u origin master1.在执行
$ git remote addorigin git@github.com:defnngj/hello-world.git
错误提示:fatal: remote origin already exists.
解决办法:
$ git remote rm origin然后在执行:
$ git remote add origin git@github.com:defnngj/hello-world.git 就不会报错误了
2. 在执行
$ git push origin master
错误提示:error:failed to push som refs to.......
解决办法:
$ git pull origin master // 先把远程服务器github上面的文件拉下来,再push 上去。删除:
$ rm test.txt$ git rm test.txt$ git commit -m "remove test.txt"