第一步:安装git。 apt-get install git

第二步:配置用户名和密码:

git config –global user.name “XXX”

git config –global user.email “XXX”

配置完后在根目录下会生成.gitconfig文件。里面就记录了刚才配置的用户名和邮箱,也可以使用git config –list来查看

第三步:为GitHub账户添加SSH Keys。ssh-keygen -t rsa -C "xx@xxx"。这个邮箱和在github上注册的邮箱保持一致。在生成的时候会提示生成的文件名。这里命令为git_hub

Generating public/private rsa key pair.

Enter file in which to save the key (/root/.ssh/id_rsa): git_hub

Enter passphrase (empty for no passphrase):

Enter same passphrase again:

Your identification has been saved in git_hub.

Your public key has been saved in git_hub.pub.

The key fingerprint is:

SHA256:QTabcdedbBdfdf1237Wxkjdkfdiidfdf21 maple412@163.com

The key's randomart image is:

+---[RSA 2048]----+

| .ooo   B+.      |

|o.oo.. @ oo      |

|o=+.  % o  .     |

|.o...= = +       |

|   . .E S o      |

|    o+.+ + .     |

|   .o ..= o      |

|     o  .+ .     |

|      .. .o      |

+----[SHA256]-----+

完成后在~/.ssh下就会生成git_hub以及git_hub.pub文件。

第四步:赋值SSH Key到GITHUB

打开前面生成的git_hub.pub文件,将其中的秘钥添加到github上去:登录github-> Settings-> SSH and GPG Keys-> New SSH key添加

第五步: 测试是否连接成功

sh -T git@github.com

The authenticity of host 'github.com (13.250.177.223)' can't be established.

RSA key fingerprint is SHA256:nThbg6kXUpJWGl7E1IGOCspRomTxdCARLviKw6E5SY8.

Are you sure you want to continue connecting (yes/no)? yes

Warning: Permanently added 'github.com,13.250.177.223' (RSA) to the list of known hosts.

Permission denied (publickey).

提示认证被拒绝

用ssh -T git@github.com进行测试下。看到有如下的输出。查找私秘钥id_rsa/id_dsa/id_ecdsa/id_ed25519 没有找到。

debug1: Authentications that can continue: publickey

debug1: Next authentication method: publickey

debug1: Trying private key: /root/.ssh/id_rsa

debug1: Trying private key: /root/.ssh/id_dsa

debug1: Trying private key: /root/.ssh/id_ecdsa

debug1: Trying private key: /root/.ssh/id_ed25519

debug1: No more authentication methods to try.

Permission denied (publickey).

原因在于前面生成私秘钥的时候我们指定了生成的文件名为git_hub.pub。因此有2个解决办法:

1 生成私秘钥的时候就按照默认的id_rsa文件名生成

2 通过ssh-add方法将生成的秘钥文件加入。先执行eval `ssh-agent` 。然后执行ssh-add ~/.ssh/git_hub。ssh-add –l就能看到我们的秘钥文件了

此时再执行连接测试,就可以连接成功了

Warning: Permanently added the RSA host key for IP address '52.74.223.119' to the list of known hosts.

Hi maple412! You've successfully authenticated, but GitHub does not provide shell access.

下面来看下如何上传工程到github上去。

1 点击New repository, 然后填下仓库代码的信息

2 点击clone or download复制仓库代码的URL

3 执行命令:git clone https://github.com/maple412/c_prj.git

正克隆到 'c_prj'...

remote: Enumerating objects: 3, done.

remote: Counting objects: 100% (3/3), done.

remote: Total 3 (delta 0), reused 0 (delta 0), pack-reused 0

展开对象中: 100% (3/3), 完成

完成后,将会创建c_prj文件夹,其中包含了.git以及README

drwxr-xr-x  3 root root 4096 3月   5 14:02 .

drwx------ 11 root root 4096 3月   5 14:02 ..

drwxr-xr-x  3 root root 4096 3月   5 14:02 c_prj

root@testnb:~/git_prj# cd ./c_prj

root@test-nb:~/git_prj/c_prj# ls -al

总用量 16

drwxr-xr-x 3 root root 4096 3月   5 14:02 .

drwxr-xr-x 3 root root 4096 3月   5 14:02 ..

drwxr-xr-x 8 root root 4096 3月   5 14:02 .git

-rw-r--r-- 1 root root   33 3月   5 14:02 README.md

root@test-nb:~/git_prj/c_prj# cat README.md

4 生成一个需要上传的文件。echo "test for git commit" >  test.txt 。此时执行git status发现test.txt为红色,这是因为还未提交的缘故。

5 执行git add --all将所有的文件都添加进git,如果只想添加某些文件,就将--all替换为你想提交的文件名,执行完后再用git status查看已经变成绿色了

6 执行git commit

git commit -m 'test'

[master 2016693] test

1 file changed, 1 insertion(+)

create mode 100644 test.txt

然后再执行git push,下面的结果表示已经push 成功

对象计数中: 3, 完成.

Delta compression using up to 8 threads.

压缩对象中: 100% (2/2), 完成.

写入对象中: 100% (3/3), 281 bytes | 281.00 KiB/s, 完成.

Total 3 (delta 0), reused 0 (delta 0)

To https://github.com/maple412/c_prj.git

9c4d0d2..2016693  master -> master

此时在github上也能看到上传的文件了

一 创建github账号以及上传工程到github的更多相关文章

  1. 上传工程到github

    这里主要讲讲如何在mac底下使用github,我刚开始使用时,还是费了一点功夫的,因为网上的资料比较杂,有些不是太准确.故将自己的安装过程比较详细的分享下,方便有需要的人,攒点人品. 首先你得完成如下 ...

  2. 如何用git命令行上传本地代码到github

    注意:安装的前提条件是配置好Git的相关环境或者安装好git.exe,此处不再重点提及 上传的步骤: 本文采用git 命令界面进行操作,先执行以下两个命令,配置用户名和email[设置用戶名和e-ma ...

  3. 直接利用本地git上传项目到github

    http://m.blog.csdn.net/article/details?id=50441442 本文将详细介绍如何托管你的项目到github上   转载请标明出处: http://blog.cs ...

  4. Intellij idea上传项目到github

    操作前提 1.安装了 git for windows客户端 2.配置了rsa公钥 3.设置了邮箱和用户名 详情请看上一篇博客http://www.cnblogs.com/520playboy/p/66 ...

  5. 用命令行在本地创建一个库并上传到Github

    1  如何在本地创建一个仓库并上传到github? 基本步骤: $ mkdir blog //在桌面上创建一个叫"blog"的目录 $ cd blog //"cd blo ...

  6. github入门到上传本地项目【网上资源整合】

    [在原文章的基础上,修改了描述的不够详细的地方,对内容进行了扩充,整合了网上的一些资料] [内容主要来自http://www.cnblogs.com/specter45/p/github.html#g ...

  7. github入门到上传本地项目

    GitHub是基于git实现的代码托管.git是目前最好用的版本控制系统了,非常受欢迎,比之svn更好. GitHub可以免费使用,并且快速稳定.即使是付费帐户,每个月不超过10美刀的费用也非常便宜. ...

  8. iOS如何上传代码到Github

    iOS如何上传代码到Github 很多iOS开发者想开源自己的代码或者demo,开源到Github是个不错的选择,那么如何上传我们的代码到Github,令所有人可以下载使用呢?这里我们的目的很明确,就 ...

  9. 使用git上传项目到github

    来自: http://www.cnblogs.com/specter45/p/github.html GitHub是基于git实现的代码托管.git是目前最好用的版本控制系统了,非常受欢迎,比之svn ...

随机推荐

  1. jquery 操作input radio 单选框

    1.jquery选中单选框 2.jquery 取消单选框 3.判断是否选中 4.设置不可编辑

  2. PHP学习笔记(4)GD库画五角星

         <?php //加header头,不然浏览器乱码 header("content-type: image/png"); //创建画布资源 $img = imagec ...

  3. spring quartz定时任务 配置

    cronExpression表达式: 字段 允许值 允许的特殊字符秒 0-59 , - * /分 0-59 , - * /小时 0-23 , - * /日期 1-31 , - * ? / L W C月 ...

  4. JVM Specification 9th Edition (4) Chapter 4. The class File Format

    Chapter 4. The class File Format Table of Contents 4.1. The ClassFile Structure 4.2. Names 4.2.1. Bi ...

  5. 3G模块(U6300)linux下拨号上网

    U6300支持linux.Android系列嵌入式系统.作为linux内核系统,系统均会自带驱动usbserial,就没有提供专门的U6300V的USB驱动,都是加载系统的usbserial以实现对U ...

  6. gm: error while loading shared libraries: libpng15.so.15: cannot open shared object file: No such file or directory

    安装gm库产生问题 解决方案: # cat /etc/ld.so.confinclude ld.so.conf.d/*.conf# echo "/usr/local/lib" &g ...

  7. 请写出一个超链接,点击链接后可以向zhangsan@d-heaven.com发送电子邮件。

    请写出一个超链接,点击链接后可以向zhangsan@d-heaven.com发送电子邮件. <a href=”mailto: zhangsan@d-heaven.com”>发邮件</ ...

  8. 开发人员需知的Web缓存知识(转)

    什么是Web缓存,为什么要使用它? 缓存的类型: 浏览器缓存: 代理服务器缓存: 网关缓存: Web缓存无害吗?为什么要鼓励缓存? Web缓存如何工作 如何控制缓存和不缓存: HTML Meta标签 ...

  9. SQLAllocStmt与SQLFreeStmt

    1.申请语句句柄 SQLAllocStmt函数为应用程序分配语句句柄,其格式为:RETCODE SQLAllocStmt(HDBC hdbc, HSTMT FAR * phstmt) 其中, hdbc ...

  10. netty学习之路

    Netty是一个高效的提供异步事件驱动的网络通信框架,换言之,Netty是一个nio实现框架并且能简化传统的TCP.UDP.Socket编程.