设为首页 收藏本站
查看: 838|回复: 0

[经验分享] GitHub使用指南!(ubuntu)

[复制链接]

尚未签到

发表于 2016-4-16 06:16:51 | 显示全部楼层 |阅读模式
<!-- @page { margin: 2cm } P { margin-bottom: 0.21cm } H2 { margin-bottom: 0.21cm } H2.cjk { font-family: "宋体" } H2.ctl { font-family: "Lohit Hindi" } PRE.cjk { font-family: "宋体", monospace } A:link { so-language: zxx } -->



Github 使用指南!(下文针对linux系统而言,特指ubuntu系统)

第一步:

下载安装Git。

     
         

            使用新立得软件包管理工具(Synaptic Package Manager)安装最新版本的git。

            推荐选择安装git-core,git-gui,git-doc。

第二步:设置SSH Keys

github使用ssh keys来确保你的电脑与github的连接有安全性。设置过程很简单。

但是有几个步骤。

步骤一:检查已有的ssh keys。

$ cd ~/.ssh

如果提示说,没有这样的文件或者目录。(No such file or directory) 则跳到步骤三。否则继续。

步骤二:备份已有的ssh keys。

步骤三:产生一个新的 ssh key。

我的产生过程如下:

banxi1988@banxi:~$ ssh-keygen -t rsa -C "banxi1988@gmail.com"

Generating public/private rsa key pair.

Enter file in which to save the key (/home/banxi1988/.ssh/id_rsa):

Enter passphrase (empty for no passphrase):

Enter same passphrase again:

Passphrases do not match. Try again.

Enter passphrase (empty for no passphrase):

Enter same passphrase again:

Your identification has been saved in /home/banxi1988/.ssh/id_rsa.

Your public key has been saved in /home/banxi1988/.ssh/id_rsa.pub.

The key fingerprint is:

0c:a5:4d:a7:d8:e8:42:b2:5c:75:d0:4c:e5:ff:6a:7f banxi1988@gmail.com

The key's randomart image is:

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

| o==.o |

| . Xo+ |

| . o = + . |

| . = . o . |

| o . . S . |

| . . |

| . |

| .. E|

| ..... |

+-----------------+

banxi1988@banxi:~$

步骤四:

在gitHub里单击账户设置。点击SSH 公钥 ,点击添加另一个公钥。

打开前面生成的id_rsa.pub 文件。(可能要显示隐藏文件才能看到用gedit或者其它的编辑器打开。

注意不要编辑,添加空格或者换行。)

然后把里面的内容复制粘贴到下面的key输入栏中。

步骤五:测试一下。

banxi1988@banxi:~$ ssh git@github.com

/etc/ssh/ssh_config: line 20: Bad configuration option: X11Forwrding

/etc/ssh/ssh_config: terminating, 1 bad configuration options

banxi1988@banxi:~$

After modify the ssh_config.中间要求输入上面输入的passphrase。

banxi1988@banxi:~$ ssh git@github.com

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

RSA key fingerprint is 16:27:ac:a5:76:28:2d:36:63:1b:56:4d:eb:df:a6:48.

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

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

PTY allocation request failed on channel 0

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

Connection to github.com closed.

banxi1988@banxi:~$



步骤六:设置git的个人信息。

1. 设置用户名和email。git使用这个来验证每个提交者。除此之外github会使用这些信息来

与你的github账号相联系。下面的名字应该是你真实的名字。而不是要GitHub的用户名。

banxi1988@banxi:~$ git config --global user.name "Li HaiZhen"

banxi1988@banxi:~$ git config --global user.email "banxi1988@gmail.com"

banxi1988@banxi:~$

2. 设置GitHub的指令环。

有些工具不使用ssh来连接。为了使用这些工具。你应该找出配置好你的API Token。

在GitHub上点击。账号设置(Account Settings) ,然后点击 账号管理(Account Admin)。

在API Token一栏里有你的API ToKen。

在命令行下运行下面的代码。

banxi1988@banxi:~$ git config --global github.user banxi1988

banxi1988@banxi:~$ git config --global github.token e5ebe68d43d9820ed8d05a3d2633d7f3

banxi1988@banxi:~$

上面使用的user是指GitHub的用户名了。

最后:恭喜你!你已经正确的设置了git和gitHub。

接下来。要做的就是。1. 创建一个仓库。2. Fork 一个仓库。 3.社区化。







第二节:创建一个仓库(Create A Repo Repositories)

直接在自己的登录后进入github.com首页就可以看到, 下面一栏有四步.用来创建Repository.

直接填入项目名称就可以了.其它的可以不填.要填,这个表单也足够自解释了.

创建后之后.会跳转到一个页面.其中有指示接下来该怎么做的.

如下:

git@github.com:banxi1988/tasteHibernate.git



接下来给你自己的项目创建一个基本的Readme文件吧.

详细操作过程如下:
Global setup:

Download and install Git
  git config --global user.name "banxi1988"
  git config --global user.email banxi1988@gmail.com
        

Next steps:

  mkdir tasteHibernate
  cd tasteHibernate
  git init
  touch README
  git add README
  git commit -m 'first commit'
  git remote add origin git@github.com:banxi1988/tasteHibernate.git
  git push -u origin master
      

Existing Git Repo?

  cd existing_git_repo
  git remote add origin git@github.com:banxi1988/tasteHibernate.git
  git push -u origin master
      

Importing a Subversion Repo?

  Click here
      

When you're done:

  Continue



banxi1988@banxi:~/github/tasteHibernate$ git init

Initialized empty Git repository in /home/banxi1988/github/tasteHibernate/.git/

banxi1988@banxi:~/github/tasteHibernate$ touch README

banxi1988@banxi:~/github/tasteHibernate$ vi README

banxi1988@banxi:~/github/tasteHibernate$ git add README

banxi1988@banxi:~/github/tasteHibernate$ git commit -m 'first commit'

[master (root-commit) 6ec8aae] first commit

1 files changed, 6 insertions(+), 0 deletions(-)

create mode 100644 README

banxi1988@banxi:~/github/tasteHibernate$ git remote add origin git@github.com:banxi1988/tasteHibernate.git

banxi1988@banxi:~/github/tasteHibernate$ git push origin master

ERROR: banxi1988/tasteHibernate.git doesn't exist. Did you enter it correctly?

fatal: The remote end hung up unexpectedly

banxi1988@banxi:~/github/tasteHibernate$ git push -u origin master

Counting objects: 3, done.

Delta compression using up to 2 threads.

Compressing objects: 100% (2/2), done.

Writing objects: 100% (3/3), 383 bytes, done.

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

To git@github.com:banxi1988/tasteHibernate.git

* [new branch] master -> master

Branch master set up to track remote branch master from origin.

banxi1988@banxi:~/github/tasteHibernate$



关于Git的命令请参见Git手册.



现在我们已经可以创建了一个库了.创建了一个文件,并且提交了.并且把它推向了github.

接下来我们将做什么呢?





第三节: Fork A Repo

有些时候你发现自己想要为别人的项目做贡献.或者希望来使用别人的项目做为自己的起点.也就称之为Fork.

     
         

            Fork一个项目. 在你想fork的项目的首页.找到fork按钮.点击.

            接下来设置你本地仓库.

            A . 克隆项目.

            $ git clone git@github.com:username/projectname.git

            B. 远程配置.

            当你克隆了一个项目之后.它有一个默认的remote.叫做.origin.这是指你是在github上fork的.而不是在原来的仓库.为了跟踪原本的仓库,你需要添加另一个叫做upstream的选项.

            $cd projectname

            $ git remote add upstream git://github.com/username/projectname.git

            $ git fetch upstream

            
            接下来.你要做的就是.

            A. 推送提交.

            一旦你做出了某些提交到你fork的仓库里,你可能想要将其推送到你fork的项目去.你要做就跟平常的项目一样.

            $git push origin master

            
            接收upstream 变更.

            如果你fork的那个原来的仓库改变了,你可以使用下面的命令来更新你fork到本地的仓库.

            $ git fetch upstream

            $ git merge upstream/master

后面的更多使用指南请参考相关文档.例如创建分支等.



本指南是由banxi1988根据github提供的帮助.进行的实践之后,翻译过来的.

由于本人水平有限.所以翻译得不好,你可以向我提意见或者直接到github里面的去看帮助.

原文:http://blog.csdn.net/banxi1988/article/details/6555293

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-204541-1-1.html 上篇帖子: Ubuntu 上使用Git 下篇帖子: 在Ubuntu Server上安装Git
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表