zoukankan      html  css  js  c++  java
  • GitHub使用简单记录

    根据《GotGitHub》【1】所做的一些整理

    1. 浏览托管项目

    在GitHub的页面中可以使用键盘快捷键

    (1)按下问号(?)会在弹出窗口显示当前页面可用的快捷键。

    (2)在项目的代码浏览页按下字母“w”,弹出分支切换菜单。

    (3)按下字母“t”,开启目录树中文件查找和过滤。

    2. 项目托管

    2.1 创建新项目

    有2种办法:(1)在GitHub创建新项目;(2)从已有版本库创建,然后 remote push到GitHub

    2.1.1 在GitHub创建新项目

    (1)在GitHub首页 “New repository”,创建新版本库 HelloWorld

    (2)在本地使用Git Bash,将repository clone到本地。

    $ git clone https://github.com/zhchnchn/HelloWorld.git

    (3)在本地HelloWorld目录下创建 README.md 文件。

    以扩展名.md,.mkd,.mkdn,.mdown,.markdown等为结尾的文件,均以Markdown标记语言语法进行解析并显示。

    (4)添加README.md文件并提交。

    $ git add README.md

    $ git commit -m "README for this project."

    (5)向GitHub推送,完成版本库初始化。

    $ git push origin master

    (6)然后刷新GitHub上HelloWorld项目的首页,可见版本库包含了一个新的提交。

    (7)如何删除创建的版本库?

    在HelloWorld项目首页的右方,点击”Settings“->在红色的”Danger Zone“区域,点击”Delete this repository“->输入项目名HelloWorld确认删除。

    如果本地clone的版本库不需要了,则手动删除之。

    2.1.2 从已有版本库创建

    (1)使用Git Bash在本地建立一个Git版本库。

    $ mkdir HelloWorld
    $ cd HelloWorld
    $ git init

    (2)然后在版本库中添加README.md文件
    $ git add README.md
    $ git commit -m "README for this project."

    (3)为版本库添加名为origin的远程版本库
    $ git remote add origin git@github.com:zhchnchn/HelloWorld.git

    (4)执行推送命令,完成GitHub版本库的初始化。注意命令行中的-u参数,在推送成功后自动建立本地分支与远程版本库分支的追踪。
    $ git push -u origin master

    注:这一步没有成功,显示错误信息。

    remote: Repository not found.
    fatal: repository 'https://github.com/zhchnchn/HelloWorld.git/' not found

     尝试了很多种方法都没有解决,有可能公司网络防火墙禁止了SSH操作。

    2014-05-20,NOTE:

    换了另外一种方式成功了:

    (1)-(2)步骤与前面相同

    (3)为版本库添加名为origin的远程版本库
    $ git remote add origin https://github.com/zhchnchn/HelloWorld.git

    (4)执行推送命令

    $ git push origin master

    提示错误:

    remote: Repository not found.
    fatal: repository 'https://github.com/zhchnchn/HelloWorld.git/' not found

    (5)在GitHub主页创建HelloWorld仓库,注意不要添加README.md等任何文件。
    (6)创建完成后,再次git push origin master,这次终于成功了。

    $ git push origin master
    Counting objects: 12, done.
    Delta compression using up to 4 threads.
    Compressing objects: 100% (12/12), done.
    Writing objects: 100% (12/12), 25.02 KiB | 0 bytes/s, done.
    Total 12 (delta 4), reused 0 (delta 0)
    To https://github.com/zhchnchn/HelloWorld.git
     * [new branch]      master -> master

     2014-05-21,NOTE:

     在 http://www.cnblogs.com/plinx/archive/2013/04/08/3009159.html中提到,使用 SSH来git remote add origin时,出现了Repository not found的问题。而在我本机上SSH不可以,HTTPS可以。说明我本机不支持SSH协议。

    2.2 在不同电脑上git push同个github账户下的repositories

    参考【2】。

    3. 公钥认证管理

    开发者向GitHub版本库写入最常用到的协议是SSH协议,因为SSH协议使用公钥认证,可以实现无口令访问,而若使用HTTPS协议每次身份认证时都需要提供口令.

    但是,可以通过在文件~/.netrc中写入明文口令实现使用 HTTPS 协议时也能自动完成认证。具体格式参见ftp命令的MAN手册中相关介绍。

    具体设置参见:http://www.cnblogs.com/zhcncn/p/3681209.html -- 如何配置,在向Github去 git push 时不用输入用户名密码?

    4. 建立主页

    4.1 创建个人主页

    GitHub 为每一个用户分配了一个二级域名<user-id>.github.io,用户为自己的二级域名创建主页很容易,只要在托管空间下创建一个名为<user-id>.github.io的版本库,向其master分支提交网站静态页面即可,其中网站首页为index.html.

    访问网址: http://gotgithub.github.io/

    要注意访问用户二级域名的主页要使用HTTP协议非HTTPS协议.

    4.2 创建项目主页

    GitHub会为每个账号分配一个二级域名<user-id>.github.io作为用户的首页地址。实际上还可以为每个项目设置主页,项目主页也通过此二级域名进行访问。例如gotgithub用户创建的helloworld项目如果启用了项目主页,则可通过网址http://gotgithub.github.io/helloworld/访问.

    为项目启用项目主页很简单,只需要在项目版本库中创建一个名为gh-pages的分支,并向其中添加静态网页即可。

    References

    【1】GotGitHub (http://www.worldhello.net/gotgithub/index.html

    【2】在不同电脑上git push同个github账户下的repositories(http://yulijia.net/cn/%E7%9F%A5%E8%A1%8C%E5%B9%B6%E8%BF%9B/2013/02/06/use-one-github-account-on-two-computers.html)

  • 相关阅读:
    Win10删除anaconda重装
    anaconda python no module named 'past'的解决方法
    detectMultiScale 读取冲突的一个解决方法
    [原] Android快速开发框架-AndroidFine,GitHub开源
    [原] Android 自定义View 密码框 例子
    [原]发布一个jQuery提示框插件,Github开源附主站,jquery.tooltips.js
    [原] Jenkins Android 自动打包配置
    [原] Android性能优化方法
    阿里云9折推荐码:0LGVW2
    [原]那些年整理的Linux常用命令,简单明了
  • 原文地址:https://www.cnblogs.com/zhcncn/p/3731707.html
Copyright © 2011-2022 走看看