zoukankan      html  css  js  c++  java
  • Git工具:Widows下的使用(提交到Github)

    2016年12月9日17:07:07

    Git工作原理

    http://deweixu.me/2016/11/05/how-git-works/  

    2016年12月1日14:25:23

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

    参考:http://www.cocoachina.com/ios/20160212/15024.html

    [转载]git初始化

    一、git基本配置
    在https://github.com/中下载git后,安装并运行git
    1.首先检测SSH keys,若已经存在key,则直接进入第三步

    cd ~/.ssh

    2.将原来的SSH keys备份并删除

    mkdir key_backup
    cp id_rsa* key_backup
    rm id_rsa*

    3.创建一个新的SSH key

    复制代码
    ssh-keygen -t rsa -C "your_email@youremail.com"
    Creates a new ssh key using the provided email Generating public/private rsa key pair.
    #此处输入将要保存的路径,默认为当前路径
    Enter file in which to save the key (/Users/your_user_directory/.ssh/id_rsa):<press enter>
    输入回车后提示输入一个类似于密码的自定义的通行证号,如果直接回车则为空
    Enter passphrase (empty for no passphrase):<enter a passphrase>
    #提示重新输入以便确认输入是否正确
    Enter same passphrase again:<enter passphrase again>
    复制代码

    如果看到Your public key has been saved等信息则说明保存成功
    4.将SSH key输入到GitHub网站中
    在:Account Settings->SSH Pbulic Keys>单击Add another public key
    将刚才新建的key输入到key中并且添加一个标题,例如:git-tutorial。即/Users/your_user_directory/.ssh/id_rsa。默认情况下.ssh是隐藏文件,需要将系统设置成显示隐藏文件才能看到。输入完成后单击Add key后,会看到git-tutorial已经被添加进去了。

    输入指令:pbcopy < ~/.ssh/id_rsa.pub   或者 clip < ~/.ssh/id_rsa.pub  拷贝

    登陆github 进入 SSH keys 

    13.png

    添加刚刚拷贝的东西

    Snip20160116_40.png

    Snip20160116_41.png

    添加完成之后是这样的

    Snip20160116_43.png


    5.测试是否能够正确链接到github中,输入以下命令:

    ssh -T 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后,显示出下列信息表示连接成功
    Hi username! You've successfully authenticated, but GitHub does not provide shell access

    执行完输入的:ssh -T git@github.com  这条指令之后会输出  Are you sure you want to continue connecting (yes/no)?  输入 yes 回车

    回到github,刷新网页就可以看到钥匙旁的灰色小圆点变绿,就表明已经添加成功了。

    Snip20160116_44.png

    二、配置个人信息
    当上面步骤完成后,就可以设置一些基本的个人信息了
    1.设置用户名和邮箱
    Git通过检测用户名和邮箱来跟踪进行commit的用户

    git config --global user.name "Firstname Lastname"
    git config --global user.email "your_email@youremail.com"

    2.设置GitHub网站标记
    单击网站中的Account Settings>Account Admin,将APT Token中的那串字符串记录下来,输入到下列命令中:

    git config --global github.user username
    git config --global github.token 获取到的token

    三、创建一个新的代码库
    打开网站中的创建代码库按钮,或直接使用https://github.com/repositories/new链接打开。
    输入相应的信息后单击创建按钮。
    实例:
    1.创建完成后在本地创建一个文件夹并在该文件夹下创建一个README文件

    mkdir ~/Hello-World 在user目录下创建一个名为Hello-World的项目文件夹(~代表用户目录,即:C:Documents and Settings当前登陆系统的用户名)
    cd ~/Hello-World 更改当前目录到Hello-World目录中
    git init 初始化该文件夹,将会提示以下信息:
    Initialized empty Git repository in /Users/your_user_directory/Hello-World/.git/
    touch README

    2.创建完README以后就需要添加并提交文件了

    git add README
    git commit -m "first commit"

    至此已经将要更改的文件提交到头信息中,但并没有真正提交到网站上去,还需要执行下面两个命令:

    git remote add origin git@github.com:gbyukg/zf-tutorial.git(若是第一次提交该项目的文件或是修改项目文件名后则需要这行这个命令,以后就可不用执行该命令)
    git push -u origin master
    

      

     =================

    每一次的提交,都需要输入

    Username

    Password 

    这两个是Github的登录名和密码,而非修改者(user.name设置)的用户名和密码

    例如,下边的:

    (首先说明,我的github上的仓库地址是:https://github.com/mywebgit/first ,登录名是mywebgit)

    git push -u origin master
    Username for 'https://github.com': origin
    Password for 'https://origin@github.com':
    remote: Invalid username or password.
    fatal: Authentication failed for 'https://github.com/mywebgit/first/'
    

      这样肯定提交或Push失败,因为登录用户名错误,应该是这样:

    D:GITREP~1BEGINU~1>git push -u local-author master
    Username for 'https://github.com': mywebgit
    Password for 'https://mywebgit@github.com':
    Counting objects: 3, done.
    Delta compression using up to 2 threads.
    Compressing objects: 100% (3/3), done.
    Writing objects: 100% (3/3), 377 bytes | 0 bytes/s, done.
    Total 3 (delta 0), reused 0 (delta 0)
    To https://github.com/mywebgit/first
       7ffed78..bd840fe  master -> master
    Branch master set up to track remote branch master from local-author.
    
    
  • 相关阅读:
    1908-逆序对(归并板子)
    4939-Agent2-洛谷
    1020-导弹拦截-洛谷
    5239-回忆京都-洛谷3月赛gg祭
    5238-整数校验器-洛谷3月赛gg祭
    最大子矩阵
    最长上升子序列(LIS)
    Zk单机多实例部署
    Zk集群部署
    zk单点部署
  • 原文地址:https://www.cnblogs.com/942267027wzmblog/p/6121841.html
Copyright © 2011-2022 走看看