
第一次接触git是使用git来提交自己的github的代码,在new repository之后,github会给出一些操作示例。
示例如下:
…or create a new repository on the command line
echo "# hello" >> README.md
git init
git add README.md
git commit -m "first commit"
git remote add origin git@github.com:XXXX/hello.git
git push -u origin master
…or push an existing repository from the command line
git remote add origin git@github.com:XXXX/hello.git
git push -u origin master
…or import code from another repository
You can initialize this repository with code from a Subversion, Mercurial, or TFS project.
如果你是第一次使用git来提交github在执行
git push -u origin master
会报错Permission denied (publickey)。
解决方案:
1.(在本地建立自己的SSH key对,并将公钥上传到github就行了。)在git上执行
ssh-keygen -t rsa
之后会提示输入一些东西,直接按回车就好了(反正我是如此)
2.执行完上述操作后,会出现
说明生成了SSH Key到本地文件.ssh/id_rsa.pub(我的在c/Users/qin/.ssh/id_rsa)中,用记事本打开,并将里面的内容复制到粘贴板上。
3.打开github的Settings,
找到SSH and GPG keys进入后添加点击New SSH key
其中title不重要随意填就好了,将复制的内容拷贝到key中。
如果不出意外的话,现在可以进行提交了。
参考文档:http://jingyan.baidu.com/article/a65957f4e91ccf24e77f9b11.html