GitHub使用

配置git

Ubuntu:sudo apt-get install git-core

RedHat:sudo yum install git

$ git config --global user.name "Your Name Here"

$ git config --global user.email "your_email@youremail.com"

$ ssh-keygen -t rsa -C "your_email@youremail.com"

$ ssh -v git@github.com

验证失败,把公钥 ./ssh/id_rsa.pub 拷贝到GitHub

$ ssh -v git@github.com

就可以看到验证成功

创建Repository

必须首先在GitHub网站上创建项目

本地初始化项目

$ rails new sanbaoyuan

$ cd sanbaoyuan/

$ git init

$ git add .

$ git commit -m "create project"

$ git remote add origin git@github.com:scige/sanbaoyuan.git

$ git push -u origin master

有没有 "-u" git 的动作是一样的。
差別在于当你使用 -u 之后,git 会记录这笔 remote 与 branch 的对应
以后你只需要下 git push,他就会自动认为你要下 git push origin master

历史版本

在服务器版本库里回退某个版本

git revert COMMIT

git push

在本地版本库里回退到某个版本

git reset --hard COMMIT

不能提交改动

常见问题

$ git remote add origin https://github.com/scige/sanbaoyuan.git

如果使用https会出现下面的错误信息

error: The requested URL returned error: 401 while accessing https://github.com/scige/sanbaoyuan.git/info/refs
fatal: HTTP request failed

官方教程不靠谱

https://help.github.com/articles/create-a-repo

参考

http://stackoverflow.com/questions/7438313/pushing-to-git-returning-error-code-403-fatal-http-request-failed


ssh出现错误信息

Agent admitted failure to sign using the key

解決方式:把私钥加进来
$ ssh-add   ~/.ssh/id_rsa

 

原文地址:https://www.cnblogs.com/scige/p/2628967.html