GitHub的搭建,使用

      Git是一个分布式的版本控制系统,最初由Linus Torvalds编写,用作Linux内核代码的管理。在推出后,Git在其它项目中也取得了很大成功,尤其是在Ruby社区中。目前,包括Rubinius、Merb和Bitcoin在内的很多知名项目都使用了Git。Git同样可以被诸如Capistrano和Vlad the Deployer这样的部署工具所使用。

    最近发现下载资料,项目代码的时候,很多开源的项目代码都托管到Github上了,平常自己在公司写代码,在家写代码,两者之间代码同步是个问题,果断学习一下

一、注册一个GitHub账号

官方地址:https://github.com/

二、新建一个仓库

1. 点击右上角+,选择New repository

New repository menu

2. 在输入框里填上仓库的名称,不能重复,顺便填上描述信息

Public and private repository options

3. 然后记得勾选这个选项

Initialize with a readme checkbox

4.最后点击Create repository.

Create repository button

到此,你已经创建完成库了,具体可参考官方文档:https://help.github.com/articles/create-a-repo/

5. 现在开始,提交,更新库里的信息了

   如下:点击README.md.

Readme file in file list

6. 如下图,可以修改里面的信息,作为项目介绍

New content in file

7. 最后填上更改备注,勾选上:Create a new branch for this commit and start a pull request

Propose file change button

ok,提交代码完成了

三, 以上为在web端进行的代码提交,接下来为使用github for windows客户端进行代码管理,方便至极

1. 安装步骤参考(本文省略安装步骤):   http://jingyan.baidu.com/article/6b97984d9bd6ed1ca2b0bf07.html

2. 安装好后打开GitHub,用你的GitHub账号登陆。

3. 在电脑所有程序里找到Git Shell,打开,需要使用命令先把远程代码克隆本地

4. 在web页面里,找到你的代码路径,复制

Clone URL button

5.然后,在本地新建一个文件夹,然后通过Git Shell进入该文件夹

执行命令:以下地址为你复制的代码地址
git clone https://github.com/myname/mycode
6. 然后回车,如下结果,成功
   如果遇到错,请参考:http://blog.chinaunix.net/xmlrpc.php?r=blog/article&uid=20682147&id=4888109
git clone https://github.com/myname/mycode
# Cloning into `mycode`...
# remote: Counting objects: 10, done.
# remote: Compressing objects: 100% (8/8), done.
# remove: Total 10 (delta 1), reused 10 (delta 1)
# Unpacking objects: 100% (10/10), done.
7. 此时进入Git Gub客户端,进行克隆导入,即可
 
 



效果演示:https://github.com/holdon521/highchart

以下为使用git bash提交项目的步骤:
1、先建立github的远程仓库【自行百度,网上有一堆】;

2、下载gitbash安装好;

3、进入gitbash命令控制台,进行远程仓库克隆;

使用命令有:

git clone https://github.com/XXXXXXXXXXX/XXXXXXXXXX.git//后面的clone地址在自己建好的github项目里可以找到【选择clone时选择UseHttps即可】
等待git命令进行远程代码克隆完成,就可以在本地自己建的仓库里面看到克隆下来的代码;

这时就可以自己在本地进行代码的修改编写;

编写完成后继续进行下面步骤;

4、使用git status查看自己要提交的修改地方【如新增了一个readme.txt文件】,会出现如下图:



5、接下来就是提交步骤:


git add readme.txt
git commit -m 'xxxxxxxxx'//后面的xxxxxxxxx是为了进行版本控制,可以在提交时添加日志记录
git remote add origin https://github.com/xxxxxxxxxxx/xxxxxxxxxxxx.git
git push origin master
若是进行git remote add origin https://github.com/xxxxxxxxxxx/xxxxxxxxxxxx.git,出现错误:


fatal: remote origin already exists
则继续进行一步:

git remote rm origin
再继续执行git remote add origin https://github.com/xxxxxxxxxxx/xxxxxxxxxxxx.git

若是进行push是报错:

error:failed to push som refs to.......
则继续使用下面命令进行上传:

git pull origin master
6、值得注意的一点使用https链接【https://github.com/xxxxxxxxxxx/xxxxxxxxxxxx.git】进行克隆和上传时若是文件过大可能会出现超时情况【 fatal: The remote end hung up unexpectedly】此时可以修改url使用ssh进行上传:


Step1:

ssh-keygen -t rsa -C "email@domain.com" //根据你的邮箱生成一个sshkey

生成成功后,在本地会保存一个私钥,然后将公钥放到gitlab上:

Step2:
cat ~/.ssh/id_rsa.pub //执行后出现表示成功ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC6eNtGpNGwstc....

​


Step3:
修改git 的url为 远程仓库中的SSH:【git@server:username/project.git】
git remote set-url origin git@gitserver:USERNAME/PROJECT.git


原文地址:https://www.cnblogs.com/holdon521/p/4705221.html