github 入门


1 注册帐号

   在https://github.com/ 上注册一个自己的帐号, 注册好之后的域名为https://github.com/moonfighting

2 安装和配置git

  在Linux下执行命令

 

sudo apt-get install git
git 就安装好了,这样就可以在本地使用命令来对github上的内容进行管理

安装好了之后,还需要进行账户的配置

执行命令

git config --global user.name "moonfighting"
git config --global user.email "moonfighting@hotmail.com"

双引号里的内容就是你注册时使用的邮箱和用户名

然后我们需要生成ssh密钥,具体步骤如下

首先检查ssh文件夹中的文件

cd ~/.ssh
ls
# Lists the files in your .ssh director
看文件夹中是否有文件存在,刚开始一定什么都没有,接下来执行命令

ssh-keygen -t rsa -C "moonfighting@hotmail.com"      
# Creates a new ssh key, using the provided email as a label
# Generating public/private rsa key pair.
# Enter file in which to save the key (/home/you/.ssh/id_rsa):
ssh-add id_rsa

这里只要一直按回车用默认设置就行了

之后会要求输入密码,照做就可以

执行成功会显示信息

Your identification has been saved in /home/you/.ssh/id_rsa.
# Your public key has been saved in /home/you/.ssh/id_rsa.pub.
# The key fingerprint is:
# 01:0f:f4:3b:ca:85:d6:17:a1:7d:f0:68:9d:f0:a2:db your_email@example.com
接下来将id_rsa.pub中的内容添加到github上

为了保证格式正确,我们可以采用github上的教程来复制文件里的内容

sudo apt-get install xclip
# Downloads and installs xclip. If you don't have `apt-get`, you might need to use another installer (like `yum`)

xclip -sel clip < ~/.ssh/id_rsa.pub
# Copies the contents of the id_rsa.pub file to your clipboard

执行上面这段代码,id_rsa.pub里的内容就黏贴到了剪切版里,

然后我们到github上的账户设置,找到ssh keys,然后点add key  ,title随便写,将剪切版里的内容粘贴到keys下面的空白处,然后点add keys就可以了。

测试是否能连通,执行命令

ssh -T git@github.com

如果显示

Hi username! You've successfully authenticated, but GitHub does not
# provide shell access.
则证明配置成功。

3 创建一个项目

   在github上点击 https://github.com/new 创建新项目hello-world

   然后在终端下创建一个新目录 hello-world

   cd 进入这个目录后

 

$ makdir ~/hello-world    //创建一个项目hello-world
$ cd ~/hello-world    //打开这个项目
$ git init    //初始化 
$ git add hello.cpp   //更新文件
$ git commit -m 'first commit'//提交更新,并注释信息“first commit” 
$ git remote add origin git@github.com:moonfighting/hello-word.git   //连接远程github项目  
$ git push -u origin master   //将本地项目更新到github项目上去
依次执行上述的命令
再登陆github就可以看到hello.cpp这个文件已经被上传上去了

如果需要修改的话,之需要

git add [file]

git commit -m 'anything'

git push origin master

就可以了

以上是github的入门,更多的功能还有待去探索

------------------------------

可能出现的几个错误,转自http://www.cnblogs.com/fnng/archive/2011/08/25/2153807.html

1.在执行

$ 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 上去。


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值