zoukankan      html  css  js  c++  java
  • GitHub使用

    1. 介绍

    这里介绍如何使用GitHub等代码托管工具的基本使用;下面主要以GitHub例来介绍其使用,Gitee基本相同

    2. 配置

    首先需要注册GitHub账号;然后我们需要Git客户端,Linux默认安装;Windows可以使用msysgit

    $ ssh-keygen -t rsa -C "your_email@youremail.com"
    /*
     * 生成ssh key
     * 命令完成之后会生成~/.ssh或%UserProFile%.ssh文件夹
     * 打开id_rsa.pub, 复制key到GitHub::Account Settings –> SSH Keys –> Add SSH Key
     */
    
    $ ssh -T git@github.com
    You've successfully authenticated, but GitHub does not provide shell access 
    
    $ git config --global user.name "your name" 
    $ git config --global user.email your_email@youremail.com
    /*
     * 配置用户名和邮箱
     */

    后来笔者在使用过程中发现每次提交时都提示:

    warning: LF will be replaced by CRLF

    经查阅发现原来是autocrlf默认开启的缘故;可使用如下命令将其关闭(或直接修改etc目录下的gitconfig文件)

    $ git config --global core.autocrlf false

    具体可参考<Git中的AutoCRLF与SafeCRLF换行符问题>

    3. 使用

    GitHub使用有两种方式

    3.1 方式一

    先在GitHub上先创建一个新的Repository,然后在本地将其clone下来;然后修改或新增文件,提交修改,最后上传

    $ git clone https://github.com/username/project.git 
    $ (一系列操作) 
    $ git status                        /* 查看版本库的状态。可以知道哪些文件发生了变化 */
    $ git add .                         /* 提交改动到本地仓库,在git commit之前必须的操作 */
    $ git commit -m "commit"            /* 提交当前工作目录的修改内容 */ 
    $ git push origin master            /* 将本地仓库推送到远程服务器* /

    3.2 方式二

    在GitHub项目初始化之前,数据已经存在于本地版本库中
    本地建立一个Git版本库,修改并提交数据,最后再通过推送完成GitHub版本库的初始化

    $ mkdir testProj
    $ cd testProj
    $ git init                        /* 本地建立一个Git版本库 */
    $ echo “This is a test” > README.md
    $ git add .                       /* 提交改动到本地仓库,在git commit之前必须的操作 */
    $ git commit -m "test for new project from local."
    $ git remote add origin git@github.com:username/testProj.git
    $ git push -u origin master /* 执行推送命令,完成GitHub版本库的初始化 */

    4. 更多

    Gitee:       Gitee Wiki
    GitHub:     GitHub Help

    其他代码托管网站有: Bitbucket, Coding, GitLab

  • 相关阅读:
    N-Queens
    Pow(x, n)
    Maximum Subarray
    Spiral Matrix
    Jump Game
    Merge Intervals
    Insert Interval
    Length of Last Word
    Spiral Matrix II
    Amazon 面经
  • 原文地址:https://www.cnblogs.com/hzl6255/p/3320971.html
Copyright © 2011-2022 走看看